dkeene Posted May 25, 2020 Posted May 25, 2020 Hello, all. If I create a new unigui component at runtime: var aNewUniComponent: TObject; begin aNewUniComponent:=TUniDBMemo.Create(self); ... then I wish to associate it with a Data Field. I know it's a data-aware control, so I should be able to do the following: TUniDBEdit(aNewUniComponent).DataField:='aFieldName'; whether it's a TUniDBEdit, TUniDBMemo, TUniDBNumberEdit, etc. This fails, however, with an access violation, although I am not sure why, and only works with the exact same class: TUniDBMemo(aNewUniComponent).DataField:='aFieldName'; otherwise I may get an Invalid Pointer Operation error. My Question is if there is a Class from which all data-aware unicontrols descend such that I can typecast without access violations, such as TUniDBControl(aNewUniComponent).DataField:='aFieldName'; Other wise I need to use a series of if then else statements like: if ClassName='TUniDBEdit' then TUniDBEdit(aNewComponent).DataField:='aFieldName' else if ClassName='TUniDBMemo' then TUniDBMemo(aNewComponent).DataField:='aFieldName' else if ClassName='TUniDBNumberEdit' then TUniDBNumberEdit(aNewComponent).DataField:='aFieldName' else etc. or perhaps there is a better way? Thank you in advance Doug 1 Quote
x11 Posted May 26, 2020 Posted May 26, 2020 may be if assigned(aNewComponent) then begin if aNewComponent is TUniDBEdit then begin TUniDBEdit(aNewComponent).DataSource := ...; TUniDBEdit(aNewComponent).DataField := ...; end; if aNewComponent is TUniMemoEdit then ... end; Quote
dkeene Posted May 28, 2020 Author Posted May 28, 2020 Thank you x11. I am trying to avoid a giant list of "if aNewcomponent is TUniDBEdit else if aNewComponent is TUniDBNumberEdit .. else if aNewComponent is TUniDB... there might be a way of saying TUniDBBaseControl(aNewComponent).Datafield... Thanks Doug Quote
x11 Posted May 28, 2020 Posted May 28, 2020 look in the documentation where the "datafield" property appeared http://www.unigui.com/doc/online_help/api/uniDBEdit_TUniDBEdit.html Quote
x11 Posted May 28, 2020 Posted May 28, 2020 http://www.unigui.com/doc/online_help/api/!!MEMBERTYPE_Properties_uniDBEdit_TUniCustomDBEdit.html typecast to TUniCustomDBEdit Quote
x11 Posted May 28, 2020 Posted May 28, 2020 another solition: check propery uses System.TypInfo; function HasDataFieldProp(AControl: TControl): Boolean; begin Result := IsPublishedProp(AControl, 'DataField'); end; https://stackoverflow.com/questions/48584888/checking-if-component-has-a-text-property Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.