Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2006.03.19;
Скачать: CL | DM;

Вниз

How to workaround missing TComponent ? with FindObj ?   Найти похожие ветки 

 
Dodfr   (2005-07-12 20:06) [0]

I want to list all components in a form but TComponent do not exist with KOL.

Goal is to pass all existing Edit, CheckBox, Radio, Combo ... and save or restore their value into/from some .ini file.

In VCL I used to do something like :

for i:=0 to Components.count-1 do
begin
 if Component[i] is TEdit then ....
 if Component[i] is TCombobox then ...
end;

Any idea ?

I tried USE_NAMES to activate FindObj to on contrary side, have a .ini file containing Components names and try to find them to get their value but once I find the PObj, how to know if it is Edit, Radio, ComboBox ...

I read in kol source that TObj.AncestorOfObject is intended to replace "is" but I don"t know how I could use it to now the type of object.


 
ECM ©   (2005-07-13 15:27) [1]

try this:

type
PControlAccess = ^TControlAccess;
TControlAccess = object(TControl)
end;

var
C: PControl;
S: String;
...
C:=Form.Children[I];
S := PControlAccess(C).get_ClassName;
...


 
Dodfr   (2005-07-13 20:14) [2]

Do not work :

TControlAccess = object(TControl)
-> Error : Local class, interfaces or object types not allowed


 
fellix   (2005-07-13 21:02) [3]

You do something wrong. It works.
Example:

{ KOL MCK } // Do not remove this line!
{$DEFINE KOL_MCK}
unit Unit1;

interface
...
implementation
...
type
 PControlAccess = ^TControlAccess;
 TControlAccess = object(TControl)
 end;

procedure TForm1.Button1Click(Sender: PObj);
 begin MsgOK(PControlAccess(Sender).get_ClassName); end;

end.


 
ECM ©   (2005-07-13 21:10) [4]

I had in view of, that TControlAccess should be declared globally.. Same it is elementary.

type
 PControlAccess = ^TControlAccess;
 TControlAccess = object(TControl)
end;

procedure TForm1.XXXXXXXXXXXX
var
 C: PControl;
 S: String;
begin
...
C:=Form.Children[I];
S := PControlAccess(C).get_ClassName;
...


 
Thaddy   (2005-07-19 12:19) [5]

If you only use standard Tcontrol descendants, you can also use the public property subclassname, which is slightly less powerfull than using USE_NAMES, but generates smaller code.
AncestorOfObj tells only if it descents from a particular Tobj derived control. For a true Tcontrol or proper Tcontrol descendant, the returned value is therefore always the same, so it does not give the information you need. With some thought - and some hacks - you can retrieve more information by inspecting the creation parameters of the windows API class, to obtain other information.
I have some code examples that simulates almost full RTTI this way.
It is a forms designer (a far more complex one than on my website)


 
Thaddy   (2005-07-19 12:27) [6]

Remark:

Why not simply always read and write all values? Like Tcontrol itself....
This may give a larger inifile, but Tcontrol is written in such a way that setting or getting dummy parameters is not harmfull.
You can than simply enumerate all children (always Tcontrol) and use the same values for all controls. This generates by far the smallest code! because you can skip the if/else/if code.
In my opinion you must have a very good reason to do it otherwise if the only thing is to write and read the values to and from an inifile.
I can do this in about 10 lines of code plus one for every property



Страницы: 1 вся ветка

Текущий архив: 2006.03.19;
Скачать: CL | DM;

Наверх




Память: 0.45 MB
Время: 0.015 c
4-1132859053
homm
2005-11-24 22:04
2006.03.19
Изменение порядка прорисовки


15-1140752459
Ученик чародея
2006-02-24 06:40
2006.03.19
Когда вам станет не хватать хранилища на 18 экзабайт данных?


4-1135232696
Юра Тихомиров
2005-12-22 09:24
2006.03.19
Дефрагментация жесткого диска


15-1140767820
vidiv
2006-02-24 10:57
2006.03.19
gigabyte GA-8ipe1000


3-1138354243
Barsky
2006-01-27 12:30
2006.03.19
Как сделать выборку не чувствительную к регистру?





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский