-
Content Count
1406 -
Joined
-
Last visited
-
Days Won
22
Everything posted by programmerdelphi2k
-
Localization of constant arrays - best practice?
programmerdelphi2k replied to Fr0sT.Brutal's topic in General Help
here in RAD 11.3 just repormemoryleaks = true and show it! -
Localization of constant arrays - best practice?
programmerdelphi2k replied to Fr0sT.Brutal's topic in General Help
and if you use this .... a "tmp" to do it and after you just "empty it"... then, the memory leak doesnt happens... implementation {$R *.dfm} const src_arr: array [1 .. 3] of string = ('foo', 'bar', 'quz'); procedure TForm1.Button1Click(Sender: TObject); var LTmpToTheTask: PString; // PUnicodeString; begin Memo1.Lines.AddStrings(src_arr); Memo1.Lines.Add(''); // // PString(@src_arr[1])^ := src_arr[1] + ' translated: Hello'; // imitate dynamically-created string // LTmpToTheTask := @src_arr[1]; // a hack LTmpToTheTask^ := 'hello world'; // Memo1.Lines.AddStrings(src_arr); // LTmpToTheTask^ := ''; // PString(LTmpToTheTask)^ := ''; // PUnicodeString(LTmpToTheTask)^ := ''; end; initialization ReportMemoryLeaksOnShutdown := true; finalization end. -
Localization of constant arrays - best practice?
programmerdelphi2k replied to Fr0sT.Brutal's topic in General Help
as said above by Glienke after a reportmemoryleaks = true -
How to get image dimension from images in TImageCollection?
programmerdelphi2k replied to softtouch's topic in VCL
@softtouch you can try some like this type TForm1 = class(TForm) ImageCollection1: TImageCollection; Memo1: TMemo; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} uses System.TypInfo; type ThelpToTWICImageFormat = record helper for TWICImageFormat function ToString: string; end; { ThelpToTWICImageFormat } function ThelpToTWICImageFormat.ToString: string; begin result := GetEnumName(typeinfo(TWICImageFormat), ord(self)).Remove(0, 3); end; procedure TForm1.Button1Click(Sender: TObject); var LICItem : TImageCollectionItem; LImage : TWICImage; LText : string; LImgCount: integer; begin LText := ''; LImgCount := ImageCollection1.Count; // for var i: integer := 0 to (LImgCount - 1) do begin LICItem := ImageCollection1.Images[i]; LText := LText + Format('Item (names): %s, sub-images: %d', [LICItem.Name, LICItem.SourceImages.Count]); // for var j: integer := 0 to LICItem.SourceImages.Count - 1 do begin LImage := LICItem.SourceImages.Items[j].Image; LText := LText + slinebreak + Format('....Sub-Image: %d W=%d, H=%d, format: %s', { } [j, LImage.Width, LImage.Height, LImage.ImageFormat.ToString]); end; // if (i < LImgCount) then LText := LText + slinebreak + slinebreak; end; // if LText.IsEmpty then LText := 'no images found'; // Memo1.Text := LText; end; end. -
you can use PopUp (it is a FORM behind scene) with any other control into it, including your TListBox!
-
Line number at build/compile time??
programmerdelphi2k replied to Ian Branch's topic in General Help
@Ian Branch I see it... but a magic-button massages the ego -
Line number at build/compile time??
programmerdelphi2k replied to Ian Branch's topic in General Help
@Ian Branch no thanks, no likes 😂 -
Line number at build/compile time??
programmerdelphi2k replied to Ian Branch's topic in General Help
@Ian Branch you can try assign "AssertErrorProc" used by system to get some info on exception... here some samples https://stackoverflow.com/questions/7214213/how-to-get-line-number-at-runtime -
Unfortunately, just because IS IN THE Documentation, does not mean that is true!
-
for sure this can be seen on Pallete of component ...
-
@Alex40 For me PopUp works as expected in Android 11 (64bits) / RAD Studio 11.3 TForm1 = class(TForm) Popup1: TPopup; Button1: TButton; Button2: TButton; Button3: TButton; procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single); procedure Button1Click(Sender: TObject); procedure FormTap(Sender: TObject; const Point: TPointF); ... implementation {$R *.fmx} uses FMX.DialogService; procedure TForm1.Button1Click(Sender: TObject); begin TDialogService.ShowMessage('hello, Im ' + TButton(Sender).Name); // Popup1.IsOpen := false; end; procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single); // desktop begin if Button = TMouseButton.mbRight then Popup1.IsOpen := true; // Embarcadero recomend "IsOpen = true/false"... end; procedure TForm1.FormTap(Sender: TObject; const Point: TPointF); // mobile begin Popup1.IsOpen := true; end; screen-20230620-155343.mp4
-
Debug don't starts in DelphiCE 11
programmerdelphi2k replied to Nicolò Blunda's topic in Delphi IDE and APIs
@Nicolò Blunda normally, you can have problem with "DPROJ" setup when using old projects with new editions (or vice-versa). then try create a new "project" for each edition, then each "DPROJ" files will have settings expected for each RAD edition.. did you understood? createa new project (VCL/FMX) delete the first form (default) - let the project empty now, just add your old units/forms/etc... save this project in a new folder... ex.: projectX\RAD10 ... projectX\RAD11 -- and original project (DPROJ) will be intact! now you'll have the same app with DPROJ files and setting for each IDE -
@alogrep As always, opinions are just opinions! And, that's why forums like this exist: to agree, to disagree, to add or subtract the parts that could be! But as we can see, and you are a very old actor and with more experience than me, then, you and I must agree that in a production environment we should not experiment, the most suitable place being a laboratory computer. And, indeed, the RAD installer (at least in the latest editions) tries at all costs to do the right thing, however, everyone knows that it does not do it with flying colors. When trying to uninstall the previous version, the installer just deletes some information and files, and "leaves behind" a lot of important information and files, as is the case of the hidden folders that RAD creates in "ProgramData" and "AppData", in addition to keys in the MSWindows Registry, and this is really the cause of many bugs or inconsistencies in the update to the new version when we confirm: "YES proceed with the uninstallation"! When I said "I prefer a fresh install", I really meant it: uninstall the current version of RAD and reboot the operating system; Delete all RAD keys in the Registry: HCU and HLM Embarcadero keys; Delete all residual folders and files (hidden or not) on disk Delete all environment variables in the "PATH" variable of the operating system; after all this long journey, then yes, I do the "fresh install of the new version of RAD Studio" Yes, it's a bit of an arduous task, but it saves a lot of hot-headed hours... and since I only do this once with each new edit, so that's ok with me... and without any other hiccups, from Embarcadero-land... everything seems to work as expected... now just re-install the components and get on with life. Of course, in a corporate environment this is not desired! But for every sentence there must be a condemned! Then the team manager will determine the best options... after all we can have a server as the central point of our RAD Studio installation, can't we? Finally, when necessary, we can assemble a new PC and leave it as our laboratory for all the tests we want without jeopardizing production. I HATE WELLCOME PAGES / SVNs 🙂 I delete it from registry !!!
-
@alogrep my prefere is always a "new fresh install", but others using the "updating" as expected... but we know Embarcadero and its bugs... then... you know. can you try my "tutorial" for test if is possible at least run without errors? https://en.delphipraxis.net/topic/9205-delphi-1023-stack-overflow-error-opening-any-project/?do=findComment&comment=76626 any way, I think that is better a new fresh install... at last case!
-
Google allows you to set an accent color for your push notifications. If you don't set a custom accent color, Android will use a grey accent color. by default only White/Black is used on alphacolor... any other should show a "white square"
-
@AlanScottAgain / @vfbb would be this... all icons should be "Opaque White" for all resolutions in Android / Options / Icons / Notifications: all your custom icons in all res = color: Opaque White <-- mandatory change the "Accent Color" for your choice you can create all XML file customized and add it manually in your "Deploy project menu" this files: colors.xml, splash_image_def.xml, strings.xml, styles.xml, styles-v21.xml is build after your "BUILD" command in IDE, then, just do it and copy for another place, do the changes, and add it your "Deploy" menu (before add new custom XML, uncheck old (default) files used by Delphi, of course) --> but this is not necessary at all... if you dont need any customization! NOTE: a "colors.xml" file has this content: (FF0000 = red in my choice) <?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <color name="notification_accent_color">#FF0000</color> </resources>
-
you can try send this command after your task (updating app)... // // a sample using a Timer but you can use only the commands: WindowState and SetForeGroundWindow() // procedure TForm1.FormCreate(Sender: TObject); begin Timer1.Interval := 3000; Timer1.Enabled := true; Caption := 'Timer enabled...'; end; procedure TForm1.Timer1Timer(Sender: TObject); begin Timer1.Enabled := false; // Self.WindowState := TWindowState.wsNormal; // SetWindowPos(Handle, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_SHOWWINDOW); SetForeGroundWindow(Self.Handle); //BringWindowToTop(Application.Handle); Caption := 'restoring window state... all task concluded!'; end;
-
Delphi 10.2.3 - Stack Overflow Error Opening Any Project
programmerdelphi2k replied to James Steel's topic in Delphi IDE and APIs
@James Steel by default, a new user always will use a "default first time run"... --> all setup is copyed from \HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Embarcadero keys... in fact, all components belong for each "session", then, in each "key" on Registry you can see it! -- and all files/folder is in your disk, nothing is delete of course! of course, a simple copy "values" in key to key would can solve it, but it's not always simple ... and for avoid any problem, you need just open the projects (DPK) "build/install it again (be using "installer" or just "Add BPL = components in your new "session/user", (updateing Path Library/Browser Path/DCU path, etc... ) you see? for that a new "build/install" is preferible! you can try this: ( for yourself risk...) export keys used for "old-sesssion" to reg file... (right-click on key root where you desire export it) now, open this file "reg" with a editor, like Notepad++ and change all old-keys to new keys (new user session) now, "import" this reg file and your Registry will have old values used in new keys(user) theorically, it would can works! --- But my preference is "build/install" or update the paths and add new components (Components-Add = BPLs) -
How to set event handler for generic TControl descendant using RTTI
programmerdelphi2k replied to CoMPi74's topic in General Help
@CoMPi74 try this way too: type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private // OR... strict private procedure DoOnClick(Sender: TObject); procedure DoMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); end; ... procedure MySetEventHandler(AObj: TObject; AEventName: string; AMethod: TMethod); begin if IsPublishedProp(AObj, AEventName) then SetMethodProp(AObj, AEventName, AMethod); end; procedure TForm1.Button1Click(Sender: TObject); var LNewButton : TButton; LNewButtonName: string; LMethod: TMethod; begin DateTimeToString(LNewButtonName, '_ss_zzz', now); // LNewButton := TButton.Create(self); LNewButton.Name := 'Btn' + LNewButtonName; LNewButton.Parent := self; LNewButton.Left := random(ClientWidth - LNewButton.Width); LNewButton.Top := random(ClientHeight - LNewButton.Height); // LMethod.Data := @LNewButton; LMethod.Code := @TForm1.DoOnClick; MySetEventHandler(LNewButton, 'OnClick', LMethod); // works! // LMethod.Data := @LNewButton; LMethod.Code := @TForm1.DoMouseUp; // namespace.proceduralType = method MySetEventHandler(LNewButton, 'OnMouseUp', LMethod); // works! end; procedure TForm1.DoMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin ShowMessage('OnMouseUp ' + TControl(Sender).Name); end; procedure TForm1.DoOnClick(Sender: TObject); begin ShowMessage('OnClick ' + TControl(Sender).Name); end; -
How to set event handler for generic TControl descendant using RTTI
programmerdelphi2k replied to CoMPi74's topic in General Help
@CoMPi74 uses System.TypInfo; type // procedural type: reference a method of an instance object TMyNotifyToMouseUp = procedure(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer) of object; procedure MySetEventHandler(AObj: TObject; AEventName: string; AMethod: TMethod); begin if IsPublishedProp(AObj, AEventName) then begin // TMethod = record Code, Data: Pointer; ... SetMethodProp(AObj, AEventName, AMethod); end; end; procedure TForm1.Button1Click(Sender: TObject); var LNewButton : TButton; LNewButtonName : string; LEventProp : TNotifyEvent; // TNotifyEvent = procedure(Sender: TObject) of object; LEventNotifyToMouseUp: TMyNotifyToMouseUp; begin DateTimeToString(LNewButtonName, '_ss_zzz', now); // LNewButton := TButton.Create(self); LNewButton.Name := 'Btn' + LNewButtonName; LNewButton.Parent := self; LNewButton.Left := random(ClientWidth - LNewButton.Width); LNewButton.Top := random(ClientHeight - LNewButton.Height); // LEventProp := DoOnClick; MySetEventHandler(LNewButton, 'OnClick', TMethod(LEventProp)); // LEventNotifyToMouseUp := DoMouseUp; MySetEventHandler(LNewButton, 'OnMouseUp', TMethod(LEventNotifyToMouseUp)); end; procedure TForm1.DoMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin ShowMessage('OnMouseUp ' + TControl(Sender).Name); end; procedure TForm1.DoOnClick(Sender: TObject); begin ShowMessage('OnClick ' + TControl(Sender).Name); end; initialization ReportMemoryLeaksOnShutdown := true; randomize; end. -
did you see this page https://melander.dk/delphi/gifimage/ "How do I make a transparent GIF?"
-
Firemonkey DLL: loading a TBitmap in initialization fails (solved)
programmerdelphi2k replied to Alexander Halser's topic in FMX
@Alexander Halser Correct me if I dont understand your propose... I did this test using a DLL (by default Wizard Delphi...) and 2 projects FMX/VCL... of course, exists many differences between 2 frameworks, than the TBitmap class too!!! initially uncompatible to exchange data directly... then I did this: you're using "PNG" in a VCL Bitmap, I think that needs a "uses pngimage = Imaging.pngimage = Vcl.Imaging.pngimage;" library prjDLL; // for tests, uncomment and build it for each platform: // {$DEFINE FireMonkeyVersion } {$UNDEF FireMonkeyVersion } // // ----------------------------------------- // {$DEFINE VCL } // {$UNDEF VCL } uses System.SysUtils, System.Classes {$IFDEF FireMonkeyVersion} , FMX.Graphics {$ELSE} , Vcl.Graphics {$ENDIF}; {$IFDEF FireMonkeyVersion} function MyLoadBitmap(AFilename: string; var ABmp: TBitmap): boolean; var LFMXBmp: TBitmap; begin result := false; // LFMXBmp := TBitmap.Create; try try LFMXBmp.LoadFromFile(AFilename); // // FMX -> bmp.SetSize before bmp.CopyFromBitmap ABmp.SetSize(LFMXBmp.Size); ABmp.CopyFromBitmap(LFMXBmp); // result := true; except // ??? end; finally LFMXBmp.Free; end; end; {$ELSE} function MyLoadBitmap(AFilename: string; var ABmp: TBitmap): boolean; begin result := false; // try ABmp.LoadFromFile(AFilename); // result := true; except // ??? end; end; {$ENDIF} exports MyLoadBitmap; var XBmp: TBitmap; begin // this is called first than function above... // // just for test to DLL initialization... Vcl/Fmx XBmp := TBitmap.Create; try MyLoadBitmap('D:\RADStudioTests\RADRX113Tests\__TEMP\FMX_DLL\MyBitmap.bmp', XBmp); finally XBmp.Free; end; end. unit uFMXFormMain; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, Winapi.Windows, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Objects, FMX.Controls.Presentation, FMX.StdCtrls, FMX.Memo.Types, FMX.ScrollBox, FMX.Memo; type TForm1 = class(TForm) Button1: TButton; Image1: TImage; Memo1: TMemo; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.fmx} type TMyProcessHeader = function(AFilename: string; var ABmp: TBitmap): boolean; var MyDLLPath: string = 'D:\RADStudioTests\RADRX113Tests\__TEMP\FMX_DLL\DLL\Win32\Debug\prjDLL.dll'; MyProcess: string = 'MyLoadBitmap'; procedure TForm1.Button1Click(Sender: TObject); var LDLLHandle: NativeUInt; LProcess : TMyProcessHeader; LBmp : TBitmap; begin LDLLHandle := LoadLibrary(PWideChar(MyDLLPath)); // if (LDLLHandle > 0) then begin try LProcess := GetProcAddress(LDLLHandle, PWideChar(MyProcess)); // if (@LProcess <> nil) then begin LBmp := TBitmap.Create; try try LProcess('D:\RADStudioTests\RADRX113Tests\__TEMP\FMX_DLL\MyBitmap.bmp', LBmp); except on E: Exception do Memo1.Text := E.Message; end; // if (LBmp <> nil) and not(LBmp.IsEmpty) then begin Image1.Bitmap.SetSize(LBmp.Size); Image1.Bitmap.CopyFromBitmap(LBmp); end; finally LBmp.Free; end; end; finally FreeLibrary(LDLLHandle); LDLLHandle := 0; end; end; end; initialization ReportMemoryLeaksOnShutdown := true; end. unit uVCLFormMain; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls; type TForm2 = class(TForm) Button1: TButton; Image1: TImage; Memo1: TMemo; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form2: TForm2; implementation {$R *.dfm} type TMyProcessHeader = function(AFilename: string; var ABmp: TBitmap): boolean; var MyDLLPath: string = 'D:\RADStudioTests\RADRX113Tests\__TEMP\FMX_DLL\DLL\Win32\Debug\prjDLL.dll'; MyProcess: string = 'MyLoadBitmap'; procedure TForm2.Button1Click(Sender: TObject); var LDLLHandle: NativeUInt; LProcess : TMyProcessHeader; LBmp : TBitmap; begin LDLLHandle := LoadLibrary(PWideChar(MyDLLPath)); // if (LDLLHandle > 0) then begin try LProcess := GetProcAddress(LDLLHandle, PWideChar(MyProcess)); // if (@LProcess <> nil) then begin LBmp := TBitmap.Create; try try LProcess('D:\RADStudioTests\RADRX113Tests\__TEMP\FMX_DLL\MyBitmap.bmp', LBmp); // if not(LBmp.Empty) then Image1.Picture.Bitmap.Assign(LBmp); except on E: Exception do Memo1.Text := E.Message; end; finally LBmp.Free; end; end; finally FreeLibrary(LDLLHandle); LDLLHandle := 0; end; end; end; initialization ReportMemoryLeaksOnShutdown := true; end. -
search between two dates
programmerdelphi2k replied to Analyste2023's topic in RTL and Delphi Object Pascal
Serge, there are so many possibilities that we often forget the obvious... good times when there weren't so many options 😂 -
Parse Json String
programmerdelphi2k replied to grantful's topic in Algorithms, Data Structures and Class Design
here a sample to convert a JSON to Dataset uses REST.Response.Adapter, System.JSON; procedure JsonToDataset(aDataset : TDataSet; aJSON : string); var JObj: TJSONArray; vConv : TCustomJSONDataSetAdapter; begin if (aJSON = EmptyStr) then begin Exit; end; JObj := TJSONObject.ParseJSONValue(aJSON) as TJSONArray; vConv := TCustomJSONDataSetAdapter.Create(Nil); try vConv.Dataset := aDataset; vConv.UpdateDataSet(JObj); finally vConv.Free; JObj.Free; end; end; -
Parse Json String
programmerdelphi2k replied to grantful's topic in Algorithms, Data Structures and Class Design
@grantful a FDMemTable can load data from many type, including JSON. you can understand "that ARRAY" in your JSON as been a "table", then if exists an array into another array, is as a Master-Detail relationship. you see? in your REST Debugger you can determinate "what the root", or be "where" you desire get the data on JSON result... look at on results tab... later this, just copy/paste the components for your project... JSON root Element = RESULTs[ 0 ] Results[ 0 ].TableABC https://docwiki.embarcadero.com/RADStudio/Alexandria/en/REST_Debugger_Tool what it would be "get info"?