Using Spring, when I declare a smart pointer for a record
SmartPerson = IShared<Pperson>;
And then create it
Smartperson := Shared<PPerson>.Make;
*by the way, think this is really cool.
How then do I go about getting RTTI on the smart pointer? Obviously, I know it's based on a TPerson record, but what steps are needed to sort of reverse what happens when Spring allocates the pointer in the first place?
I see when the record pointer is created it uses code like this
tkPointer: IShared<Pointer>(Result) := Shared.TRecordFinalizer.Create(TypeInfo(T));
followed by code like this
constructor Shared.TRecordFinalizer.Create(typeInfo: PTypeInfo);
var
Size : integer;
begin
inherited Create;
fTypeInfo := typeInfo.TypeData.RefType^;
size := GetTypeSize(fTypeInfo);
fValue := AllocMem(Size);
end;
My Question is how do I get, for example, a field of the record the smart pointer points to by using the smart pointer itself?
Hope that makes sense, and maybe another dumb question.
To give some more background to problem. I have a factory which uses RTTI to build a control for a field of a record.
procedure TForm3.Button1Click(Sender: TObject);
begin
Task := Shared<pTaskRecord>.make;
Task.AnalysisDates.ES := now;
Task.TaskType := TTaskTypes.DelayTask;
ControlFactory := TControlFactory.create(Self);
Edit := Controlfactory.GetControl('TAnalysisDates','ES');
if assigned(Edit) then
begin
AddObject(Edit.Invoke);
Edit.Value := @Task.AnalysisDates;
end;
end;
Which works. It returns an TDateEdit based on attribute tags on a record
I was thinking perhaps what I could do is this
Edit := Controlfactory.GetControl(Task,Task.ES);
//passing in my smart pointer, along with field
then the factory would have everything it needs to hook the control up without having to do it in code myself.
Edit.Value := @Task.AnalysisDates;
the above line could be handled by the factory. Anyway just an idea