(0003196)
Natter
23.05.08 18:36
|
Also zumindest werden die TStringlist jetzt erstmal gespeichert. Allerdings funktioniert es noch nicht ganz sauber (die Zugewiesenen Texte stimmen nicht ganz - anscheinend wird der Zeilenumbruch als Trenner interpretiert).
function script_utils_WriteObjToString(Obj: TObject): String;
type
TWriteToScriptString = function(slf: TObject): String;
var
func: TWriteToScriptString;
begin
if IsObject(Obj) then
begin
result:=Obj.ClassName+'|:';
if Obj is TStringList then
result:='TStringList|:'+TStringList(Obj).Text
else
begin
func:=Obj.MethodAddress('WriteToScriptString');
if Assigned(func) then
result:=result+TWriteToScriptString(func)(Obj)
else
result:='nil';
end;
end
else
result:='nil';
end;
function script_utils_ReadObjFromString(Str: String; aClass: TClass): TObject;
type
TReadFromScriptString = function(slf: TClass; ObjStr: String): TObject;
var
Parts: TStringArray;
begin
if Str<>'nil' then
begin
Parts:=string_utils_explode('|:',Str);
if length(Parts)=2 then
begin
Str:=Parts[1];
if Parts[0] = 'TStringList' then
begin
result:=TStringList.Create;
TStringList(result).Text:=Parts[1];
exit;
end
else if (aClass=nil) or (aClass=TObject) then
aClass:=script_utils_GetClass(Parts[0]);
end;
result:=TReadFromScriptString(aClass.MethodAddress('ReadFromScriptString'))(aClass,Str);
end
else
result:=nil;
end; |