-
Content Count
1406 -
Joined
-
Last visited
-
Days Won
22
Everything posted by programmerdelphi2k
-
Parse Json String
programmerdelphi2k replied to grantful's topic in Algorithms, Data Structures and Class Design
uses System.JSON; procedure YourProcedure; var jsonArray: TJSONArray; jsonObject: TJSONObject; begin jsonArray := TJSONArray.Create; // Add each object to the JSON array jsonObject := TJSONObject.Create; jsonObject.AddPair('Value', 'CHRYSLER'); jsonObject.AddPair('ValueId', '477'); jsonObject.AddPair('Variable', 'Make'); jsonObject.AddPair('VariableId', '26'); jsonArray.AddElement(jsonObject); jsonObject := TJSONObject.Create; jsonObject.AddPair('Value', 'CHRYSLER DE MEXICO TOLUCA'); jsonObject.AddPair('ValueId', '1002'); jsonObject.AddPair('Variable', 'Manufacturer Name'); jsonObject.AddPair('VariableId', '27'); jsonArray.AddElement(jsonObject); jsonObject := TJSONObject.Create; jsonObject.AddPair('Value', 'PT Cruiser'); jsonObject.AddPair('ValueId', '3595'); jsonObject.AddPair('Variable', 'Model'); jsonObject.AddPair('VariableId', '28'); jsonArray.AddElement(jsonObject); jsonObject := TJSONObject.Create; jsonObject.AddPair('Value', '2003'); jsonObject.AddPair('ValueId', ''); jsonObject.AddPair('Variable', 'Model Year'); jsonObject.AddPair('VariableId', '29'); jsonArray.AddElement(jsonObject); // Convert the JSON array to a string ShowMessage(jsonArray.ToString); jsonArray.Free; end; here you had a JSONArray with 4 elements. each element has 4 pairs (key:value). some like this. now see on help to "Get" the values for i := 0 to jsonArray.Count - 1 do begin jsonObject := jsonArray.Items[i] as TJSONObject; if jsonObject.GetValue('Variable').Value = 'Model' then begin // Found the object with "Model" variable, get the "Value" value ShowMessage(jsonObject.GetValue('Value').Value); Break; end; end; -
delphi 10.4.2 invalid compiler directive
programmerdelphi2k replied to Manlio Laschena's topic in ICS - Internet Component Suite
@Manlio Laschena you can try some like this: implementation {$R *.dfm} var LArrPrompts: TArray<string>; // 3 elements LArrValues : TArray<string>; // 3 elements LAnswers : TArray<string>; // 3 elements function VerifyMyInputs(const AValues: array of string): Boolean; begin LAnswers := []; // // your rules... for var i: integer := 0 to high(AValues) do if AValues[i].IsEmpty then LAnswers := LAnswers + [LArrPrompts[i] + ' is empty']; // result := length(LAnswers) = 0; // if "0" all it's right! NOTE: im forcing "0" = true! but you can do it any other way! // if not result then // just for test on screen.. .do it as you want! Form1.Memo1.Lines.AddStrings(LAnswers); end; procedure TForm1.Button1Click(Sender: TObject); begin LArrPrompts := ['First Name', 'Last Name', 'Email']; LArrValues := ['', '', '']; // equals to LArrPrompts size! // Memo1.Lines.Clear; // if InputQuery('Caption', LArrPrompts, LArrValues, VerifyMyInputs) then Memo1.Lines.Add('ok'); end; -
delphi 10.4.2 invalid compiler directive
programmerdelphi2k replied to Manlio Laschena's topic in ICS - Internet Component Suite
@Manlio Laschena maybe a "developer" error? who knows? please, post your code in question -
@Andrew Spencer I haven't done this test yet, but what I do know is that Edge's sub-directories are created on its first run. This way, it unpacks all DLL files to generate a new repository for use, a kind of on-demand! Then, you could try deleting the directory you want to see the result, i.e. if there will be any exceptions thrown or if Edge will recreate the new sub-directory! On the other hand, I think there is a proper function to clear Edge cache. You tried to "re-create" the browser again to see the result?
-
I can't deploy my local files to the public directory of my phone, what's wrong?
programmerdelphi2k replied to jiyiwan's topic in Cross-platform
@jiyiwan Starting with Android 11, things will be even more restricted for Android developers, not just in Delphi! But not, unfortunately, for hackers! Is not it? by default you can read/write in sub-folders of the app! Using ADB (Android tools) it is possible to do some magic to overcome some barriers, however, it is necessary to master the tool and issue some line commands to your device, either via USB or Wifi!!! Nothing too easy around here! On the other hand, you could do it like this: Deploy your files etc... to the default folder used by Delphi for Android devices: assets\internal (or external if you have privileges) after the first run of your app, check and copy the desired files to other folders on the device (unfortunately, this is not possible by default, so your app needs a special permission) To get the special permission, you must necessarily ask the device user to grant it! The proposed permission is "Access all files" (MANAGE_ALL_FILES_ACCESS_PERMISSION), however this permission requires you to ask Google-Play for permission to grant it, if you distribute your application through this means! *you need add just a permission in your Android Manifest, see in your Project-Options->Permissions the list of permissions for this! This permission is easily implemented in the app, and works to access all folders on the Android device, with the exception of some system folders, such as: Android/Data and some other control ones! After getting the permission "MANAGE_ALL_FILES_ACCESS_PERMISSION" (user can revoke it), you will be able to read and write in practically all the folders of the device (with the exception of some of the system), then, you will be able to read, write, copy, delete your files. This way, your own application can move the files that were deployed to another folder, and then just use them. I can confirm that the special permission "MANAGE_ALL_FILES_ACCESS_PERMISSION" really works, however, Goggle requires you to send a request reporting "why do you need this permission in your software?", if you want to distribute your application via Google-Play, for example! *this permission is only used by Antivirus, Manager Files, etc... -
try some like this: (see if "ODD" (TBitmapData) to Bitmap works or not? ) // Ca.Canvas.Scale:=PointF(1, -1); // .X or .Y but Scale is read-only! then try change "b" scale! ... // Odd. Map(TMapAccess.Write, Id.PixelFormat); Odd := TBitmapData.Create(W, H, TPixelFormat.RGB { ? } ); ... var IdAlphaColor := Id.GetPixel(X, Y); if IdAlphaColor <> 0 then // Id.GetAlpha(J) <> 0 then begin Odd.SetPixel(X, Y, IdAlphaColor); // Id.GetPixel(J)); end else begin Odd.SetPixel(X, Y, Odd.GetPixel(X, Y - W div 2)); end; end; ... // FFrames := FFrames + [Odd.Clone]; var b:=TBitmap.Create; b.Map(TMapAccess.ReadWrite, Odd); FFrames := FFrames + [ b]; // b.Free ??? ... Odd := Default (TBitmapData); // Odd.Unmap; // Odd is "record"
-
How to see the parameters of the default style?
programmerdelphi2k replied to XylemFlow's topic in FMX
did you try save in disk using "WriteComponent" function? -
for me, yeah
-
@Osama Ghazal
-
it's quite simple: FindFirstFileEx accept: * and ? mask chars like D.O.S. or you can verify the files names before add in "AFilesFound" I forgot add this, but it's quite simple add it. 😋
-
you're wrong, my code find any file where you desire!
-
Setting & Usage of TFormatSettings..
programmerdelphi2k replied to Ian Branch's topic in General Help
FormatSettings is a "record" with global definition, then if any unit change it, you'll have its effect. but it's always prudent use a local definition to avoid any problem! mainly on thread, because it's not thread-safe! all internal definitions came from MSWindows/OS, then yes, Create() just use it. you can have how many you needs! Call GetLocaleFormatSettings to populate the TFormatSettings variable with locale information. TApplication.UpdateFormatSettings: Specifies whether format settings are updated automatically when the user alters the system configuration. Use UpdateFormatSettings to control automatic updating of format settings. The default of true is set in the constructor. Using the default format settings is recommended. These settings are initialized to the Windows local. -
here you can use a "Set" like: type TMyEnum = (meEXPREG, meEXPACC, meEXPERR, meEXPREL, meEXPREF, meEXPREQ, meEXPINF, meEXPCLA, meEXPCON, meEXPAME, meEXPIRJ, meEXPARJ, meEXPHRT); TMyEnums = set of TMyEnum; ... var MyEnums:TMyEnums; begin MyEnums :=[meEXPACC,meEXPREG]; MyExecuteMyProcs(LArrProcs, MyEnums, 'doc', 'cdn', 'correlation', 'msgtext'); end;
-
@KodeZwerg @robertjohns a little less code... if we remove the frills, we have even a little less.... if we remove everything, we have even less in my tests all is working... type TFindFileDirectory = (ffdDirectory, ffdFile); TFindFilesDirectories = set of TFindFileDirectory; TArrObjectsFound = TArray<string>; const // missing FindEx flags FIND_FIRST_EX_CASE_SENSITIVE = $00000001; FIND_FIRST_EX_LARGE_FETCH = $00000002; FIND_FIRST_EX_ON_DISK_ENTRIES_ONLY = $00000004; var LFindFileDirectory: TFindFilesDirectories; LDirRootToSearch : string = ''; function FindExcludingFolders(ARootDir: string; AListFolders: TArrObjectsFound): boolean; begin result := false; // if (ARootDir.IsEmpty) or (length(AListFolders) = 0) then exit; // for var F in AListFolders do if (LowerCase(F) = LowerCase(ARootDir)) then exit(true); end; procedure FindDirsRecursive( { } ARootDir: string; { } var ADirsFound, AFilesFound: TArrObjectsFound; { } AFindObjects: TFindFilesDirectories; { } ADirsExclude: TArrObjectsFound); var LFilename : PWideChar; LFIndexInfoLevels: TFindexInfoLevels; LFindFileData : TWin32FindData; // Pointer; LFindexSearchOps : TFindexSearchOps; // LSearchFilter : Pointer; = always null, for while in mswindows! LAdditionalFlags: cardinal; LFindResult : NativeUInt; // // LGetLastError : cardinal; LIsPointDirectory : boolean; LIsDirectory : boolean; LFileFound : string; LRootDirNormalized: string; LExcludeFolder : boolean; begin ARootDir := IncludeTrailingPathDelimiter(ARootDir); // for new IDEs LExcludeFolder := (length(ADirsExclude) > 0); // LFilename := PWideChar(ARootDir + '*.*'); LFIndexInfoLevels := _FINDEX_INFO_LEVELS.FindExInfoStandard; LFindexSearchOps := _FINDEX_SEARCH_OPS.FindExSearchLimitToDirectories; LAdditionalFlags := FIND_FIRST_EX_LARGE_FETCH or FIND_FIRST_EX_ON_DISK_ENTRIES_ONLY; // LFindResult := Winapi.Windows.FindFirstFileEx( { } LFilename, { } LFIndexInfoLevels, { } @LFindFileData, { } LFindexSearchOps, { } nil { it should be NULL } , { } LAdditionalFlags); // try // LGetLastError := GetLastError; // if (LFindResult <> INVALID_HANDLE_VALUE) then begin repeat LFileFound := LFindFileData.cFileName; // LIsPointDirectory := ((LFileFound = '.') or (LFileFound = '..')); LIsDirectory := ((LFindFileData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) <> 0); LRootDirNormalized := ARootDir + LFileFound; // // either file or directory, all in a few lines of code! if not(LIsPointDirectory) then begin if LIsDirectory and (ffdDirectory in AFindObjects) then begin if not(LExcludeFolder and FindExcludingFolders(LRootDirNormalized, ADirsExclude)) then begin ADirsFound := ADirsFound + [LRootDirNormalized]; // FindDirsRecursive(LRootDirNormalized, ADirsFound, AFilesFound, AFindObjects, ADirsExclude); end; end else begin if (ffdFile in AFindObjects) then AFilesFound := AFilesFound + [LRootDirNormalized]; end; end; // until not Winapi.Windows.FindNextFile(LFindResult, LFindFileData); end; finally if (LFindResult <> INVALID_HANDLE_VALUE) then Winapi.Windows.FindClose(LFindResult); end; end; for test: var LArrFoundDirectories: TArrObjectsFound; LArrFoundFiles : TArrObjectsFound; begin LFindFileDirectory := LFindFileDirectory + [TFindFileDirectory.ffdDirectory, TFindFileDirectory.ffdFile]; // FindDirsRecursive(Edit1.Text, { } LArrFoundDirectories, { } LArrFoundFiles, { } LFindFileDirectory, { } ['d:\_WinBackups', 'd:\AndroidStudioSDK', 'd:\DelphiEditions', { } 'd:\RADStudioTests', 'd:\RADRX112Samples', 'd:\SDKsRAD']);
-
@Osama Ghazal I think there is a basic error here! You cannot insert a new product in the price list if it does not exist in the products table, however, to insert a new product in the products table, you must inform all required fields (id, name, price, etc...) in this table. At the end, then, you could get the "ID" of this new product to use in the price list table! Thus "ID" is the primary key in the product table, and it is the foreign key in the price list table! Typical Master-Details usage!
-
if you only need to show a "form" if another one imposed a condition, like in login... try this program Project1; uses System.SysUtils {FreeAndNil()} , System.UITypes {TModalResult} , Vcl.Forms, uMainForm in 'uMainForm.pas' {Form1} , uLoginForm in 'uLoginForm.pas' {Form2}; {$R *.res} var LoginForm : TForm2; LAllItsRight: TModalResult; begin Application.Initialize; Application.MainFormOnTaskbar := True; Application.CreateForm(TForm1, Form1); // LAllItsRight := mrNo; LoginForm := TForm2.Create(nil); try LAllItsRight := LoginForm.ShowModal; finally FreeAndNil(LoginForm); // to avoid a pointer-on-space end; // if (LAllItsRight = mrOk) then Application.Run; end. /// ---- form2 = LoginForm var Form2: TForm2; implementation {$R *.dfm} procedure TForm2.Button1Click(Sender: TObject); begin Self.ModalResult := mrOK; // just set "modalresult before close it" end; end. // here, simulating a intervale to wait before close LoginForm etc... procedure TForm2.FormCreate(Sender: TObject); begin // Timer1.Enable = true by default Timer1.Interval := 3000; // 3secs end; procedure TForm2.Timer1Timer(Sender: TObject); begin Self.ModalResult := mrOK; // you can to do any actions before set "modalresult" to close it! end;
-
procedure TForm1.Button1Click(Sender: TObject); var LFind : TArray<string>; LWhereIsIt : TStringList; LFound : integer; LItemsFound: TArray<string>; begin LFind := ['some.pds', 'other.cff', 'world.exe']; LItemsFound := []; // LWhereIsIt := TStringList.Create; try LWhereIsIt.AddStrings(['hello.tt', 'other.cff', 'world.exe', 'delphi.dp', 'some.pds']); // LWhereIsIt.Sort; // mandatory to "StringList.Find()" -> many functions needs "a sorted list" // for var F in LFind do if LWhereIsIt.Find(F, LFound) then LItemsFound := LItemsFound + [F]; // if (length(LItemsFound) > 0) then begin if (length(LItemsFound) = length(LFind)) then Memo1.Lines.Add('all items was found: ' + ''.join(',', LItemsFound)) else Memo1.Lines.Add('some/all item(s) was not found: ' + ''.join(',', LItemsFound)); end else Memo1.Lines.Add('nothing was found'); finally LWhereIsIt.Free; end; end; LWhereIsIt := TStringList.Create; try LFind := ['some.pds', 'other.cff', 'world.exe']; LWhereIsIt.AddStrings(['hello.tt', 'other.cff', 'world.exe', 'delphi.dp', 'some.pds']); LHowManyItemsFound := 0; // for var F in LFind do if LWhereIsIt.DelimitedText.Contains(F) then LHowManyItemsFound := LHowManyItemsFound + 1; // if (length(LFind) = LHowManyItemsFound) then Memo1.Lines.Add('all items was found'); finally LWhereIsIt.Free; end;
-
maybe some problem with "LSP" ? verify if any message appears in your IDE (bottom panel msg window) like "restarting LSP... etc...." did you try install in another pc or vm for tests?
-
@stacker_liew I dont have StandFrame to use, then I just remove it! try change the color at "procedure TTetris.DefaultCanvas(Canvas: TCanvas);" --> Canvas.Fill.Color := TAlphaColorRec.Blue; // CurrentColor; " function TTetris.GetCurrentSprite: TSprite; begin Result := AllSpriteKind[Random(6)]; CurrentColor := Random($FFFFFF); // black over black is = black end;
-
delphi Exception illegal instruction (0xc000001d) in Windows Preinstallation Environment 8.1
programmerdelphi2k replied to hoaque's topic in Software Testing and Quality Assurance
really I dont have tested a scenary like your, but RAD is dependent of some DLL/BPL in some scenary, then, as your MS8.1 is not complete yet.. it would can when using some function from System.SysUtils not? (just expeculation) -
delphi Exception illegal instruction (0xc000001d) in Windows Preinstallation Environment 8.1
programmerdelphi2k replied to hoaque's topic in Software Testing and Quality Assurance
@hoaque my tip is look at https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Installation_Notes as your Windows is not installed yet, then, can be the "cause" etc.. -
@Ian Branch What do you expected about it? I would like understand...
-
Now was quick NOTE: I didn't check if the 133,676 files were from c:\Windows or not... 😜
-
MEA CULPA: in my code propose I forgot verify about c:\Windows and c:\Other\Windows <--- are different things! --> sorry! 😝 if not(LLookFolderToSkip and MyFoldersToSkip(AFoldersToSkip, LSearchRecord.Name)) then <--- it should be: AFolderRoot + LSearchRecord.Name now, you need this: (or some way to do it automatically... MyFindFilePattern('D:\zzTest', ['*.*'], ['D:\zzTest\Windows'], LMyResult);
-
You have to consider this, because the search must know the full path, to avoid excluding the search in a different subdirectory, for example: c:\Windows and c:\Other\Windows <--- are different things!