[fpc-pascal] Question about FORMDATA
Anon Januar-Nullacht
anon20080127 at yahoo.com
Thu Apr 8 13:19:49 CEST 2010
Hello everyone!
I'm new to FPC/Lazarus, and I would like to thank everyone involved for the great work. I have maybe a stupid question: I am trying to understand how Lazarus applies FORMDATA resources to forms. Specifically, in the standard main unit situation like this:
------- unit1.pas-------
unit Unit1;
type
TForm1 = class(TForm)
Button1: TButton;
end;
var
Form1: TForm1;
------ unit1.lfm -------
object Form1: TForm1
Left = 383
Height = 300
Top = 175
Width = 400
Caption = 'Form1'
ClientHeight = 300
ClientWidth = 400
LCLVersion = '0.9.26.2'
object Button1: TButton
Left = 151
Height = 25
Top = 137
Width = 75
Caption = 'Button1'
TabOrder = 0
end
end
-------
I consider unit.lrs to be simply a translation of unit1.lfm (right?).
Now, unit1.lrs seems to be applied in a way that the newly created TForm1 is assigned to Unit1.Form1, and the newly created TButton is both a child of Unit1.Form1 and assigned to Unit1.Form1.Button1 (right?)
I want to have a similar behavior for custom components (data keepers etc.) with or without Lazarus (I also have to do command-line tools and would like to move away from C). Like
------- myunit.pas -------
type
TMyComponent = class(TComponent)
FChild : TSomeComponent;
procedure DoSomething;
end;
var
MyComponent : TMyComponent;
implementation
procedure TMyComponent.DoSomething;
begin
// Do something with FChild
end;
------- myunit.lfm -------
object MyComponent: TMyComponent
object FChild : TSomeComponent
SomeProperty : 42
end
end
-------
However, when I use ReadComponentFromBinaryStream() or similar methods to stream properties and assign the new component (manually) to MyUnit.MyComponent, I get a TSomeComponend named FChild which is a child of MyComponent, but it is not assigned to MyUnit.MyComponent.FChild. If I call MyComponent.DoSomething, FChild is nil. This is not what I want.
Of course, I could iterate through the freshly created components after doing ReadComponentFromBinaryStream() and use RTTI for TMyComponent (and its field components) to fix references (I could do that, right?), but isn't it possible to use existing code for that? As far as I understand the RTL docs, FixupReferences() etc. have nothing to do with that (right?). So, if the code which I'm looking for exists (or the functionality is documented somewhere), where is the code/the documentation (even Delphi docs, if the implementations in Lazarus and Delphi are similar)?
Maybe related: Function pointers are always unassigned after streaming when using functions like ReadComponentFrom...(), even if i use WriteComponentTo...() (with assigned function pointers) first and then just re-read the stream. Why is that?
I hope this describes the problem/question correctly and I haven't overlooked any existing docs/discussions.
Thanks again.
ML
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20100408/50d3c722/attachment.html>
More information about the fpc-pascal
mailing list