[DUG] Pasting components from code
John Bird
johnkbird at paradise.net.nz
Fri Sep 17 12:39:48 NZST 2010
I have a source generation program to speed creating of sets of labels and
edit boxes on a form - which gives output like examples below.
I paste the code that goes in the DFM onto the form, and it creates all the
components - a neat Delphi trick for those who might not know.
My problem is that the OnEnter and OnExit events seem to disappear from
these components and I have to add them back manually, even though the code
was already in the unit when the paste was done. My detective work so far
seems to show that it depends on where the forward (first) declaration of
the event code is placed whether it is recognised or not - seems it has to
be above the {private} and {public} sections for the form
What are the rules for where such event code has to be declared? - I am
vague on this. I have heard others use generated code too, I am wondering
if they have tips or pitfalls like this to avoid.
(Aside - Personally I favour source generation like this a lot. It is cool
to do, ends up as fast as hand written code, and most importantly saves time
and introduces standard code structure that is easy to understand.)
(Further aside - this is code generated by the program for a new part of
itself. Its cool when a program can write its own code).
example of output from the code generation....
// Forward declaration
procedure edtSOURCEINPUTEnter(Sender: TObject);
procedure edtSOURCEINPUTExit(Sender: TObject);
//Implementation ------- edit enter and exit events for editing this
record --------
procedure Tform1.edtSOURCEINPUTEnter(Sender: TObject);
begin
(some code here)
end;
procedure Tform1.edtSOURCEINPUTExit(Sender: TObject);
begin
(some code here)
end;
And:
//Paste onto form
object lblSrcInpPath: TLabel
Left = 300
Top = 51
Width = 142
Height = 13
Caption = 'Path'
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object edtSrcInpPath: TEdit
Left = 420
Top = 48
Width = 121
Height = 21
Font.Charset = DEFAULT_CHARSET
Font.Color = clNavy
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 1
Text = ''
Enabled = True
OnEnter = edtSOURCEINPUTEnter
OnExit = edtSOURCEINPUTExit
end
object lblSrcInpFileIn: TLabel
Left = 300
Top = 75
Width = 142
Height = 13
Caption = 'Filename without path'
Font.Charset = DEFAULT_CHARSET
Font.Color = clBlack
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object edtSrcInpFileIn: TEdit
Left = 420
Top = 72
Width = 121
Height = 21
Font.Charset = DEFAULT_CHARSET
Font.Color = clNavy
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 2
Text = ''
Enabled = True
OnEnter = edtSOURCEINPUTEnter
OnExit = edtSOURCEINPUTExit
end
etc....
John
More information about the Delphi
mailing list