Jump to content

programmerdelphi2k

Members
  • Content Count

    1406
  • Joined

  • Last visited

  • Days Won

    22

Everything posted by programmerdelphi2k

  1. programmerdelphi2k

    Resize PNG in Delphi 11

    var MyImage: TImage; begin MyImage := TImage.Create(nil); try MyImage.Left := 0; // any values ... MyImage.Top := 0; MyImage.Width := 0; // ... MyImage.Picture.LoadFromFile('....'); // MyImage.Parent := self; // self = form1 -> "parent" to appears on screen of form area!! finally MyImage.Free; end;
  2. programmerdelphi2k

    Resize PNG in Delphi 11

    To tell the truth, you would only need to embed a "resource" (image, sound, etc...) in strictly necessary case, where to load it... would be something very time consuming, or if the resource doesn't cost much for your system (memory, performance, etc...)! Overall you could just load it "on-demand" Using a component is just to make the job easier, in fact you can create it at run-time. Or, if you don't need a component, you can just create the component class to do your background work... in code!
  3. programmerdelphi2k

    Nested TParallel.For: Immediate deadlock

    ... in a bad mood again!
  4. programmerdelphi2k

    Resize PNG in Delphi 11

    after this line, "LPictureSource" it's not necessary anymore, then, you can " LPictureSource.Graphic := nil"
  5. programmerdelphi2k

    Resize PNG in Delphi 11

    @dmitrok2006 when loading in "design-time" your image is "embedded" in you exe!
  6. programmerdelphi2k

    Resize PNG in Delphi 11

    @dmitrok2006 you need "load" your image using any way... file, stream, resource, etc...! you decide how to?
  7. you can try some like this: your JSON have 3 levels, then, you can see the values to store on table fields using the JSON class from Delphi of course, the "RECURSIVE" procedure would help here! {$R *.dfm} uses System.Generics.Collections, System.JSON; procedure TForm1.Button1Click(Sender: TObject); var LJSvalueLvl1: TJSONValue; LJSvalueLvl2: TJSONValue; LJSvalueLvl3: TJSONValue; LJSarrayLvl1: TJSONArray; LJSarrayLvl2: TJSONArray; LJSarrayLvl3: TJSONArray; LJSobjLvl1 : TJSONObject; LJSobjLvl2 : TJSONObject; LJSobjLvl3 : TJSONObject; begin // considering your JSON with 3 levels = 3 arrays! // 3 levels = Master-Details tables! // // LJSobjLvlXXX.Pairs[ xxx ].JsonString = field-names // LJSobjLvlXXX.Pairs[ xxx ].JsonValue = field-values // // TableXXX.FieldByName( LJSobjLvlXXX.Pairs[ xxx ].JsonString.ToString ).AsXXXXX := valueXXXX // valueXXXX = LJSobjLvlXXX.Pairs[ xxx ].JsonValue.ToString / "asType<T>" = "value-as-type-XXXX" // LJSvalueLvl1 := TJSONObject.ParseJSONValue(Memo1.Text, true, true); // if well-formed go ahead... // if LJSvalueLvl1 is TJSONArray then begin LJSarrayLvl1 := TJSONArray(LJSvalueLvl1); // for var I: integer := 0 to LJSarrayLvl1.Count - 1 do begin LJSvalueLvl1 := TJSONValue(LJSarrayLvl1[I]); // if LJSvalueLvl1 is TJSONObject then begin LJSobjLvl1 := TJSONObject(LJSvalueLvl1); // for var j: integer := 0 to (LJSobjLvl1.Count - 1) do begin Memo2.Lines.Add('Lvl 1 = ' + LJSobjLvl1.Pairs[j].JsonString.ToString); // if LJSobjLvl1.Pairs[j].JsonValue is TJSONArray then begin LJSarrayLvl2 := TJSONArray(LJSobjLvl1.Pairs[j].JsonValue); // for var k: integer := 0 to (LJSarrayLvl2.Count - 1) do begin LJSvalueLvl2 := TJSONValue(LJSarrayLvl2[I]); // if LJSvalueLvl2 is TJSONObject then begin LJSobjLvl2 := TJSONObject(LJSvalueLvl2); // for var l: integer := 0 to (LJSobjLvl2.Count - 1) do begin Memo2.Lines.Add('______Lvl 2 = ' + LJSobjLvl2.Pairs[l].JsonString.ToString); // if LJSobjLvl2.Pairs[l].JsonValue is TJSONArray then begin LJSarrayLvl3 := TJSONArray(LJSobjLvl2.Pairs[l].JsonValue); // for var m: integer := 0 to (LJSarrayLvl3.Count - 1) do begin LJSvalueLvl3 := TJSONValue(LJSarrayLvl3[m]); // if LJSvalueLvl3 is TJSONObject then begin LJSobjLvl3 := TJSONObject(LJSvalueLvl3); // for var n: integer := 0 to (LJSobjLvl3.Count - 1) do begin // TJSONObject = values from Lvl3 Memo2.Lines.Add('____________Lvl 3 = ' + LJSobjLvl3.Pairs[n].JsonString.ToString + '=' + LJSobjLvl3.Pairs[n].JsonValue.ToString); end; end; end; end else // TJSONObject = values from Lvl2 begin LJSobjLvl3 := TJSONObject(LJSobjLvl2.Pairs[l].JsonValue); Memo2.Lines.Add('_________Lvl 2 = value = ' + LJSobjLvl3.ToString); end; end; end; end; end else // TJSONObject = values from Lvl1 Memo2.Lines.Add('___Lvl 1 = value = ' + LJSobjLvl1.Pairs[j].JsonValue.ToString); end; end; end; end; end; end.
  8. programmerdelphi2k

    Resize PNG in Delphi 11

    I think that is VCL, not? Image1.Picture.Graphic.SetSize(...) ... procedure TForm1.Button1Click(Sender: TObject); var LPictureSource: TPicture; // load a PNG LPictureTarget: TPicture; // to resize like a Bitmap LPNGresulted : TPngImage; // to save PNG resulted begin LPictureSource := TPicture.Create; LPictureTarget := TPicture.Create; LPNGresulted := TPngImage.Create; try LPictureSource.LoadFromFile('Spiderman.png'); // with transparent background on png LPictureSource.Graphic.Transparent := True; // Memo1.Text := 'Spiderman.png = ' + LPictureSource.Width.ToString + 'x' + LPictureSource.Height.ToString; // LPictureTarget.Bitmap.Create(1, 1); // just for create internal values to canvas, etc... LPictureTarget.Graphic.Transparent := True; // // new size LPictureTarget.Bitmap.Width := Trunc(LPictureSource.Width * 4.0); // size x 4 LPictureTarget.Bitmap.Height := Trunc(LPictureSource.Height * 4.0); // // draw on new canvas resized LPictureTarget.Bitmap.Canvas.StretchDraw(LPictureTarget.Bitmap.Canvas.ClipRect, LPictureSource.Graphic); // Memo1.Lines.Add(LPictureTarget.Width.ToString + 'x' + LPictureTarget.Height.ToString); // LPNGresulted.Assign(LPictureTarget.Bitmap); // Memo1.Lines.Add('PNG = ' + LPNGresulted.Width.ToString + 'x' + LPNGresulted.Height.ToString); // LPNGresulted.SaveToFile('resulted.png'); // just for test load file... // Image1.Picture.LoadFromFile('resulted.png'); Image1.Proportional := True; finally LPNGresulted.Free; LPictureTarget.Free; LPictureSource.Free; end; end;
  9. programmerdelphi2k

    Formatting method

    when all go wrong, you can "force it" using the "comments chars alignment" to provocate your break-line! + "Ctrl+D" (IDE) ... and Formatter options... I Love it! 😍 procedure TForm1.Test( { indent comments + breakline } const Part1: integer; { } const part2: string; { } var part3: boolean); begin end; MyFormatterOptions.7z
  10. programmerdelphi2k

    Move objects to a second Data Module

    😂
  11. programmerdelphi2k

    Move objects to a second Data Module

    You could try something along these lines: you create a new "DataModule in your project" (thus, Delphi already creates the .PAS unit and the .DFM file! = more easy way! Now, you can use a procedure like the one below to read the components you want to remove from the source-datamodule and insert them into your new datamodule created above! Remembering that "InsertComponent()" will automatically try to remove the component from the source to insert it in the target! type TMyArrayOfThisComponents = TArray<string>; procedure MyInsertAllComponentsOnDM(const ADMsource, ADMtarget: TDataModule); begin while (ADMsource.ComponentCount > 0) do ADMtarget.InsertComponent(ADMsource.Components[0]); // "remove" from source and "insert" on target! end; procedure MyInsertThisComponentsOnDM(const ADMsource, ADMtarget: TDataModule; const AComponents: TMyArrayOfThisComponents); begin for var C in AComponents do // all list of components names... begin for var i: integer := 0 to (ADMsource.ComponentCount - 1) do if (ADMsource.Components[i].Name = C) then // if exists on DMsource... begin ADMtarget.InsertComponent(ADMsource.Components[i]); // "remove" from source and "insert" on target // break; // next components-name... end; end; end; procedure TForm1.BtnUsingDMonProjectClick(Sender: TObject); begin try // DataModule3/Unit3 is a DataModule created on this project, for example! // // MyInsertAllComponentsOnDM(DataModule2, DataModule3); MyInsertThisComponentsOnDM(DataModule2, DataModule3, ['FDQuery1', 'FDConnection', 'dsQuery1', '...']); // WriteComponentResFile('Unit3.dfm', DataModule3); // Unit3.pas and Unit3.DFM "already" exists in your project!!! except // ??? end; end; procedure TForm1.BtnCreatingAnewDMfileClick(Sender: TObject); var MyNewDM: TDataModule; begin MyNewDM := TDataModule.Create(nil); try MyNewDM.Name := 'MyNewDM'; try // MyInsertAllComponentsOnDM(DataModule2, MyNewDM); MyInsertThisComponentsOnDM(DataModule2, MyNewDM, ['FDQuery1', 'FDConnection', 'dsQuery1', '...']); // WriteComponentResFile('MyNewDM.dfm', MyNewDM); // // now, you needs create your "UNIT.pas" for this "MyNewDM.DFM file" like IDE do it! except // ??? end; finally MyNewDM.Free; end; end; now, you'll have your components inserted in your "new datamodule", then, you can just "ADD it" in your project, and create your "event" (or copy it from old datamodule) in the tests, the properties are kept as in the source! you would can automatizate this, but needs much more code to verify each object and your events, ...read source, write target ...
  12. programmerdelphi2k

    Puzzled by StrToDate

    I think you could create "input patterns" so you could eliminate error expectations. For each "input pattern", you could create the pre-analysis procedure/function, and at the end, the final completion code, either to show the error, or to return the value to the user in the expected format. as Delphi does, that is, procedures that call sub-procedures to find the appropriate use case (a kind of "overloads"). in general, a simple call to Delphi's standard function would be enough to check the validity or not of a date or time, otherwise, your function could continue after this first evaluation by default.
  13. programmerdelphi2k

    Move objects to a second Data Module

    WOW! That's very crazy man! in Text mode, you can find and copy/paste in second "place" (DM)... of course, very tiring, but given this tangle of objects, nothing will be very easy and reliable in an automation without any human intervention. because after copy your obj, of couse, needs pay attention on events code... in DFM mode, copy it too! 🤣
  14. programmerdelphi2k

    Const in function params

    I think that better way would be read the EMB explains https://docwiki.embarcadero.com/RADStudio/Sydney/en/Parameters_(Delphi) after, this... each case it's a case (in special case)
  15. programmerdelphi2k

    Puzzled by StrToDate

    😘
  16. programmerdelphi2k

    Puzzled by StrToDate

    using mask "MMM/d/yyyy" it's works! = no exception! Now, "Names" = month-names short! MSWindows Datetime formats: MM = nn MMM = Sss NOTE: in my RAD11.2 "mmm" works too!
  17. programmerdelphi2k

    tparallel.for/TTask only run one thread in Min/Max of chess?

    not, it'a Beta with "keygen" from "internet"
  18. programmerdelphi2k

    Vonoroi / Fortunes algorithm

    no, no! the page is working! Im using Chrome 109! you can download all ".JS" (just using the address+<<filename.JS>> to verify the code source! or use download link, if working... (for me failed...) view-source:https://voronoi-editor.web.app/src/main.js ... etc... including sub-folder/files... https://voronoi-editor.web.app/src/voronoi_app.js etc....
  19. programmerdelphi2k

    More precise countdown

    you can try use "TStopWatch" in System.Diagnostic.pas... works like a timer to measure a time, with more precision because dont use any UI event! https://www.thoughtco.com/accurately-measure-elapsed-time-1058453
  20. programmerdelphi2k

    More precise countdown

    You could try your own "Timer", but maybe you could get a little frustrated if you don't have much knowledge about "messages" from system.... In the end, the "Timer" just keeps listening and receiving messages from the operating system and filtering to see if it's a "timer" message, and, if true, it just calls a procedure to execute its "OnTimer" event. It's a session of: KillTimer(), SetTimer() non-stop. You could try to create a new class using a "Thread", and do your own calculation, and call your preferred procedure, but if Embarcadero hasn't done it better yet, it's adequate for most needs! Don't forget that every iteration with the UI will determine the delay of the triggered event, that is, its final result.
  21. programmerdelphi2k

    More precise countdown

    try this for verify your time: implementation {$R *.dfm} uses System.DateUtils; var LOldNow: TDateTime = 0; LText : string; procedure TForm1.FormCreate(Sender: TObject); begin Timer1.Interval := 1 { ms }; // 15ms mininum to return a value! end; procedure TForm1.Button1Click(Sender: TObject); begin LText := ''; LOldNow := now; Timer1.Enabled := true; end; procedure TForm1.Button2Click(Sender: TObject); begin Timer1.Enabled := false; // Memo1.Lines.Delimiter := '='; Memo1.Lines.DelimitedText := LText.Remove(0, 1); end; procedure TForm1.Timer1Timer(Sender: TObject); begin // processing time "without" visual interference!!! in release mode LText := LText + '=' + MilliSecondSpan(now, LOldNow).ToString; // LOldNow := now; end; end. I think that you'll need some "library" 3rd-party for that or you can read this article https://www.thedelphigeek.com/2007/10/calculating-accurate.html
  22. programmerdelphi2k

    App as target via "share"

    look, your app "just" will be showed if "it" is "identifyed" in your "Android manifest" with the same "MIME" that "other" apps exporting data/info/etc... the Embarcadero sample, works here (but just using MIME = "*/*") --> this a sample!!! not a final app for real-usage! IF YOU DONT WANT a sender-app.. .ok, pay attention only in RECEIVER app! if you app desire receive a file (in a universe of files...), it needs be prepared for this... you needs use "Android manifest" for that, indicating the "MIME" used in "other apps"! for this, you needs knows what is the MIME used by other app! Normally, the "apps" use the MIME known by all ---> see on Android site as above! In rare cases, a MIME (non-default) would can be used... but dont wait for a "blue sky here" Think about this: YOU expect a "cat"!!! SOMEONE send to you a "dog"!!! what do you do? --> accept a "dog" and expect a "MEAWWW" or a "AWW AWW" ?
  23. programmerdelphi2k

    App as target via "share"

    hi @schaumermal I think that the problem here is the "MIME" used to find the apps on Android! really the sample by Embarcadero DONT WORKS for me too! then, I have tested in Embarcadero DEMO project with generic "MIME" = */* and it works! You app will be showed on "choicer"! test in your project: SENDER app: use this: Intent.setType(StringToJString('*/*')); //text/pas RECEIVER app: use this on Android manifest: <data android:mimeType="*/*" /> --> //text/pas--> on intent-filter.... now, all apps that accept your send will be showed on "choicer" https://developer.android.com/reference/androidx/media3/common/MimeTypes https://android.googlesource.com/platform/external/mime-support/+/9817b71a54a2ee8b691c1dfa937c0f9b16b3473c/mime.types
  24. programmerdelphi2k

    IsValidDate fails after the Year 9999

    for sure, this will be the new "visual" for "Nigel 10K"
×