Board index » delphi » Creating Edit's, Memo's and ComboBox'es at runtime
Tzvetelin Gospodinov
![]() Delphi Developer |
Tue, 25 Nov 2003 00:30:37 GMT
|
Tzvetelin Gospodinov
![]() Delphi Developer |
Tue, 25 Nov 2003 00:30:37 GMT
Creating Edit's, Memo's and ComboBox'es at runtime
Im writing a program which must create a number of components, depending on
the information contained in an ini file. The possible components are TEdit, TMemo and TComboBox. After I create them I need to use their properties and arrange them (for example their text properties) in the exact order of the components' creation (in a single string). I know I have to create a dynamic array of TWinControls, for example and then create and put the components on the form programatically, but then I cant use their text properties... How do i do that? Thanx in advance, </end> |
Team
![]() Delphi Developer |
Tue, 25 Nov 2003 05:03:16 GMT
Re:Creating Edit's, Memo's and ComboBox'es at runtimeQuoteIn article <3b1faba1_1@dnews>, Tzvetelin Gospodinov wrote: their true classes, or by using run-time type information. The unit below may be of use here. {== Unit UIHelpers ====================================================} Uses Controls, Graphics; Procedure SetControlColor( aControl: TControl; aColor: TColor ); Implementation Uses {-- SetControlColor ---------------------------------------------------} Quote}{ Created 13.12.2000 by P. Below Procedure SetControlColor( aControl: TControl; aColor: TColor ); Begin { SetControlColor } Assert( Assigned( aControl )); If IsPublishedProp( aControl, 'Color' ) Then SetOrdProp( aControl, 'Color', aColor ); End; { SetControlColor } {-- SetControlFontColor -----------------------------------------------} Quote}{ Created 13.12.2000 by P. Below Procedure SetControlFontColor( aControl: TControl; aColor: TColor ); Begin { SetControlFontColor } Assert( Assigned( aControl )); If IsPublishedProp( aControl, 'Font' ) Then TFont( GetObjectProp( aControl, 'Font', TFont )).color := aColor; End; { SetControlFontColor } {-- GetControlColor ---------------------------------------------------} Quote}{ Created 13.12.2000 by P. Below Function GetControlColor( aControl: TControl ): TColor; Begin { GetControlColor } Assert( Assigned( aControl )); If IsPublishedProp( aControl, 'Color' ) Then Result := TColor( GetOrdProp( aControl, 'Color' )) Else Result := clWindow; End; { GetControlColor } {-- GetControlFontColor -----------------------------------------------} Quote}{ Created 13.12.2000 by P. Below Function GetControlFontColor( aControl: TControl ): TColor; Begin { GetControlFontColor } Assert( Assigned( aControl )); If IsPublishedProp( aControl, 'Font' ) Then Result := TFont( GetObjectProp( aControl, 'Font', TFont )).color Else Result := clWindowText; End; { GetControlFontColor } {-- SetControlText ----------------------------------------------------} Quote}{ Created 13.12.2000 by P. Below Procedure SetControlText( aControl: TControl; Const aText: String ); Begin { SetControlText } Assert( Assigned( aControl )); If IsPublishedProp( aControl, 'Text' ) Then SetStrProp( aControl, 'Text', aText ) Else If IsPublishedProp( aControl, 'Caption' ) Then SetStrProp( aControl, 'Caption', aText ); End; { SetControlText } {-- GetControlText ----------------------------------------------------} Quote}{ Created 13.12.2000 by P. Below Function GetControlText( aControl: TControl ): String; Begin { GetControlText } Assert( Assigned( aControl )); If IsPublishedProp( aControl, 'Text' ) Then Result := GetStrProp( aControl, 'Text' ) Else If IsPublishedProp( aControl, 'Caption' ) Then Result := GetStrProp( aControl, 'Caption' ) Else Result := EmptyStr; End; { GetControlText } End { UIHelpers }. |
1. Creating 'ODBC System DSN' at runtime
2. Creating 'ODBC System DSN' at runtime
3. Creating 'ODBC System DSN' at runtime
4. Combobox.Items.Objects becomes 'corrupt'
5. Creating RunTime Fields: EDataBaseError 'Field 'Fieldname' is not of the expected type'
6. edit text file in a web's memo control
7. Clearing all edit box's and memos in one comand
8. table1.fieldbyname('memo').asstring