Перейти к содержанию
Fire Monkey от А до Я

Лидеры

  1. Brovin Yaroslav

    Brovin Yaroslav

    Администраторы


    • Баллы

      7

    • Постов

      2 124


  2. Евгений Корепов

    Евгений Корепов

    Пользователи


    • Баллы

      4

    • Постов

      738


  3. RoschinSpb

    RoschinSpb

    Пользователи


    • Баллы

      2

    • Постов

      187


  4. SerhioUser

    SerhioUser

    Пользователи


    • Баллы

      2

    • Постов

      55


Популярный контент

Показан контент с высокой репутацией 14.03.2017 во всех областях

  1. Ссылка: http://yaroslavbrovin.ru/object_life_cycle_in_delphi_part_2_android_ios-ru/ Автор: Ярослав Бровин Продолжаем тему жизненного цикла объектов в мире Delphi, но в этой части рассматриваем эту тему в рамках мобильных платформ Android и iOS. Delphi вводит новый подход к управлению памятью в мобильных платформах. Появляется автоматический подсчет ссылок, который с одной стороны облегчает код разработчика и должен помочь ему, а с другой стороны раскладывает равномерно грабли на пути освоения новых платформ в мире Delphi.
    7 баллов
  2. Благодарю, Евгений Корепов! Вот функция GetApkVersion() на C++ для получения версии APK-файла, и слегка подкорректированная вышеописанная функция запуска: String __fastcall ShellExecutePipe(String CommandLine, String AWorkDir = "C:\\", UINT Flag = SW_HIDE) { TSecurityAttributes SA; TStartupInfo SI; TProcessInformation PI; HANDLE StdOutPipeRead, StdOutPipeWrite; bool WasOK; char Buffer[256]; unsigned long BytesRead; String WorkDir; bool Handle; String AOutputLine; String Result; SA.nLength = sizeof(SA); SA.bInheritHandle = true; SA.lpSecurityDescriptor = NULL; CreatePipe(&StdOutPipeRead, &StdOutPipeWrite, &SA, 0); try { setmem(&SI, sizeof(SI), 0); SI.cb = sizeof(SI); SI.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; SI.wShowWindow = Flag; SI.hStdInput = (unsigned)GetStdHandle(STD_INPUT_HANDLE); // don't redirect stdin SI.hStdOutput = (unsigned int)StdOutPipeWrite; SI.hStdError = (unsigned int)StdOutPipeWrite; WorkDir = AWorkDir; Handle = CreateProcess(NULL, CommandLine.c_str(), NULL, NULL, true, 0, NULL, WorkDir.c_str(), (STARTUPINFO*)&SI, &PI); } catch(Exception &e) { } CloseHandle(StdOutPipeWrite); if (Handle) { try { do { WasOK = ReadFile(StdOutPipeRead, Buffer, 50, &BytesRead, NULL); if(BytesRead > 0) { Buffer[BytesRead] = 0; AOutputLine = Buffer; Result = Result + AOutputLine; } }while(WasOK && (BytesRead != 0)); WaitForSingleObject(PI.hProcess, INFINITE); } __finally { CloseHandle(PI.hThread); CloseHandle(PI.hProcess); } } CloseHandle(StdOutPipeRead); return Result; } //--------------------------------------------------------------------------- String __fastcall GetShortName(String sLongName) { String ret; String sShortName; int nShortNameLen; sShortName.SetLength(MAX_PATH); nShortNameLen = GetShortPathName( sLongName.c_str(), sShortName.c_str(), MAX_PATH - 1); if (nShortNameLen != 0) { sShortName.SetLength(nShortNameLen); ret = sShortName; } return ret; } //--------------------------------------------------------------------------- String __fastcall GetApkVersion(String FileName) { String ret; String AppPath = GetShortName(ExtractFileDir(Application->ExeName)); FileName = GetShortName(FileName); if(FileName != "") { String cmd = (String)"cmd /c \""+ AppPath + "\\aapt.exe\"" + " dump badging " + FileName; String res = ShellExecutePipe(cmd, AppPath); TStringList *sl = new TStringList; sl->Delimiter = ' '; sl->DelimitedText = res; ret = AnsiDequotedStr(sl->Values["versionName"], '\''); if(ret != "") ret += "."; ret += AnsiDequotedStr(sl->Values["versionCode"], '\''); delete sl; } return ret; } //--------------------------------------------------------------------------- Всем спасибо за участие.
    2 балла
  3. Добавьте проверку на наличие файла. Ваш код выдает ошибку, но вы не знаете причину ошибки - отсутствие файла или ошибка в процессе LoadFromFile AFilePath:=System.IOutils.TPath.Combine(System.IOutils.TPath.GetDocumentsPath, 'Image_640x960.png'); if TFile.Exists(AFilePath) then Image2.Bitmap.LoadFromFile(AFilePath) else ShowMessage('File not found');
    2 балла
  4. Вот так напрямую в память: function ShellExecuteMy(CommandLine: string; AWorkDir: string = 'C:\') : String; var SA: TSecurityAttributes; SI: TStartupInfo; PI: TProcessInformation; StdOutPipeRead, StdOutPipeWrite: THandle; WasOK: Boolean; Buffer: array[0..255] of AnsiChar; BytesRead: Cardinal; WorkDir: string; Handle: Boolean; AOutputLine : String; begin with SA do begin nLength := SizeOf(SA); bInheritHandle := True; lpSecurityDescriptor := nil; end; CreatePipe(StdOutPipeRead, StdOutPipeWrite, @SA, 0); try with SI do begin FillChar(SI, SizeOf(SI), 0); cb := SizeOf(SI); dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES; wShowWindow := SW_HIDE; // wShowWindow := SW_MINIMIZE; // wShowWindow := SW_NORMAL; hStdInput := GetStdHandle(STD_INPUT_HANDLE); // don't redirect stdin hStdOutput := StdOutPipeWrite; hStdError := StdOutPipeWrite; end; WorkDir := AWorkDir; // Handle := CreateProcess(nil, PChar('cmd.exe /C ' + CommandLine), Handle := CreateProcess(nil, PChar(CommandLine), nil, nil, True, 0, nil, PChar(WorkDir), SI, PI); // Result:=PI; CloseHandle(StdOutPipeWrite); finally CloseHandle(StdOutPipeRead); end; if Handle then try repeat // WasOK := ReadFile(StdOutPipeRead, Buffer, 255, BytesRead, nil); WasOK := ReadFile(StdOutPipeRead, Buffer, 50, BytesRead, nil); if BytesRead > 0 then begin Buffer[BytesRead] := #0; AOutputLine:=StrOemToAnsi(Buffer); Result :=Result + AOutputLine; end; until not WasOK or (BytesRead = 0); WaitForSingleObject(PI.hProcess, INFINITE); finally CloseHandle(PI.hThread); CloseHandle(PI.hProcess); end; finally CloseHandle(StdOutPipeRead); end; end; Функция читает пайп вывода и помещает в строку. P.S. uses Winapi.Windows;
    2 балла
  5. Вот добавил пример для URL в ту же ветку, коль скоро там велось обстоятельное обсуждение. Также в ImageListDemo есть пример добавления картинки нарисованной вручную См. procedure TMainForm.AddSourceToItem(const Index: Integer);
    1 балл
  6. А вот вариант загрузки из этихвашихинтернетов из сети по заданному URL procedure TForm2.Button2Click(Sender: TObject); const SourceName = 'Картинка'; function LoadPicture(const SourceName: string; const Scale: Single; const URL: string): TCustomSourceItem; var HTTPClient: TNetHTTPClient; Stream: TMemoryStream; TmpBitmap: TBitmap; BitmapItem: TCustomBitmapItem; begin Result := nil; Stream := nil; TmpBitmap := nil; HTTPClient := TNetHTTPClient.Create(nil); try Stream := TMemoryStream.Create; HTTPClient.Get(URL, Stream); Stream.Position := 0; TmpBitmap := TBitmap.Create; TmpBitmap.LoadFromStream(Stream); if (TmpBitmap.Width > 0) and (TmpBitmap.Height > 0) then begin Result := ImageList1.Source.Add; Result.Name := SourceName; Result.MultiResBitmap.TransparentColor := TColorRec.Fuchsia; Result.MultiResBitmap.SizeKind := TSizeKind.Source; Result.MultiResBitmap.Width := Round(TmpBitmap.Width / Scale); Result.MultiResBitmap.Height := Round(TmpBitmap.Height / Scale); BitmapItem := Result.MultiResBitmap.ItemByScale(Scale, True, True); if BitmapItem = nil then begin BitmapItem := Result.MultiResBitmap.Add; BitmapItem.Scale := Scale; end; BitmapItem.Bitmap.Assign(TmpBitmap); end; finally HTTPClient.Free; TmpBitmap.Free; Stream.Free; end; end; var NewSource: TCustomSourceItem; NewDestination: TCustomDestinationItem; NewLayer: TLayer; begin if ImageList1.Source.IndexOf(SourceName) = -1 then begin NewSource := LoadPicture(SourceName, 1, 'http://voy.dk/wp-content/uploads/2010/06/Avril-lavigne-13thebestdamnthingmarkliddellshootnhy5_122_131lo-779x1024.jpg'); NewDestination := ImageList1.Destination.Add; NewLayer := NewDestination.Layers.Add; NewLayer.SourceRect.Rect := TRectF.Create(TPoint.Zero, NewSource.MultiResBitmap.Width, NewSource.MultiResBitmap.Height); NewLayer.Name := SourceName; Button1.ImageIndex := NewDestination.Index; end; end; Здесь приведен простейший вариант загрузки картинки как есть, т.е. она будет хранится в исходном размере. На телефоне может и не хватить места.
    1 балл
  7. ENERGY

    Реестр в Андроиде и Delphi

    SharedPreference удаляются при деинсталяции программы.
    1 балл
Эта таблица лидеров рассчитана в Москва/GMT+03:00
×
×
  • Создать...