Recent

Author Topic: Dynamic Creation of TSynEdit control with default settings  (Read 907 times)

simone

  • Hero Member
  • *****
  • Posts: 706
Dynamic Creation of TSynEdit control with default settings
« on: June 19, 2022, 07:22:59 pm »
I want to dynamically create a TSynEdit control with the same default settings (i.e. properties) as those created at design time. I'm thinking of doing this by transforming the portion of the .lfm file that contains these settings into code. Is there a smarter method?
Microsoft Windows 10/11 64 bit - Lazarus 4.8/4.6 FPC 3.2.2 x86_64-win64-win32/win64

dje

  • Full Member
  • ***
  • Posts: 134
Re: Dynamic Creation of TSynEdit control with default settings
« Reply #1 on: June 20, 2022, 03:36:04 am »
Create a new TFrame and copy/paste your TSynEdit onto that. You will need to copy and rebind all your notify events.

Then create the TFrame derived class via code. Usually this means adding it to dynamically created TTabSheets parented by a TPageControl.

I'm unaware of a tool which auto creates code from a pas/lfm file, but I'm sure its possible. Usually I hand convert designtime stuff to a custom class, which is a little time consuming.

You can "plonk" a TFrame derived class directly onto a TForm in design time, but I've found that to be a nightmare.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12554
  • Debugger - SynEdit - and more
    • wiki
Re: Dynamic Creation of TSynEdit control with default settings
« Reply #2 on: June 21, 2022, 12:04:46 pm »
If you have the lfm standalone (without the form data or other components in the lfm), then: TReader (and some tools in the IDE).

Otherwise, create a (binary) lfm stream from the existing SynEdit via TWriter, and then use TReader.

Something like
Code: Pascal  [Select][+][-]
  1. procedure ....
  2. var
  3.   strm: TMemoryStream;
  4.   Driver: TAbstractObjectWriter;
  5.   Writer: TWriter;
  6.   Reader: TReader;
  7. begin
  8.   strm := TMemoryStream.Create;
  9.   Driver := TBinaryObjectWriter.Create(strm,4096);
  10.   Writer := TWriter.Create(Driver);
  11.   Writer.WriteRootComponent(ASourceComp);
  12.   Driver.Free;
  13.   Writer.Free;
  14.  
  15.   strm.Position := 0;
  16.   Reader := TReader.Create(strm, 4096);
  17.   Reader.ReadRootComponent(ADestComp);
  18.   Reader.Free;
  19.  
  20.   strm.Free;
  21. end;
  22.  

 

TinyPortal © 2005-2018