#1 2013-06-21 09:04:36

lele9
Member
Registered: 2011-10-28
Posts: 170

create a TObjectList from TSQLRecordMany

hi,
i have a TSQLRecordMany descendant class.
i would like to have a method that can create a TObjectList of TSQLRecordMany.

Something like this

ObjectList := TObjectList<TSQLBaseMany>.Create;
ObjectList.OwnsObjects := True;
SQLBaseMany.FillMany(aClient, aSourceID);
while SQLBaseMany.FillOne do
begin
     ObjectList.Add(SQLBaseMany);
end;
Result := ObjectList;
FreeAndNil(SQLBaseMany);

But when i call the method for second time i get an AV on SQLBaseMany.FillOne. Can you help me to understand where i mistake?
Thanks,
Emanuele.

Offline

#2 2013-06-21 14:09:02

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,187
Website

Re: create a TObjectList from TSQLRecordMany

Where is your SQLBaseMany instance initilaized?

Offline

#3 2013-06-21 14:26:02

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: create a TObjectList from TSQLRecordMany

if i have TSQLRecordMany published property is a real instance after TSQLRecord.create, its right?

Offline

#4 2013-06-21 14:48:57

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,187
Website

Re: create a TObjectList from TSQLRecordMany

Yes, but you call FreeAndNil(SQLBaseMany); therefore you release the SQLBaseMany instance.

So how are you creating the SQLBaseMany instance?
It is not shown in your code!

And you are adding the same object instance to your list.
This is not correct, from the Delphi point of view.
You have to create a new instance each time, then fill the newly created instance.
See for instance, how methods TSQLTable.ToObjectList () or  TSQLTable.ToObjectList<T>: TObjectList<T> are implemented.

Offline

#5 2013-06-21 15:04:13

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: create a TObjectList from TSQLRecordMany

ok, forget my code. i try to explain all situation.
i have a component that taken a tObjectList is able to show and elaborate it, so i would like to get a tObjectList from a generic TSQLRecordMany property.
now, think about mORMotUIEdit and his TRecordEditForm.SetRecord procedure.
Well, i would like to implement this part of code

sftBlob, sftMany:
            ; // not implemented yet

reading a tObjectList from TSQLRecordMany property and pass it to my component.

What is the correct and fast way to do?
thanks ab for the help!

Offline

#6 2013-06-24 08:04:45

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: create a TObjectList from TSQLRecordMany

it's clear my situation and what i would like to do?
any idea?

Offline

#7 2013-06-24 12:30:57

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,187
Website

Re: create a TObjectList from TSQLRecordMany

AFAIR it is part of the feature request list, or mORMot roadmap.

Offline

#8 2013-06-25 14:14:41

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: create a TObjectList from TSQLRecordMany

yes i know, but i would like to implement but i need some help.
for example:
i read in the documentation that TSQLRecordMany property of a TSQLRecord class is an instance but...
why aValue is empty? (aValue = '')

aValue := P.GetValue(aRecord,false);
aFieldType := Fields.List[i].SQLFieldType;
        case aFieldType of
          sftDateTime: begin
            CD := TDateTimePicker.Create(Scroll);
            CD.Kind := dtkDate;
            CD.DateTime := Iso8601ToDateTime(aValue);
          end;
          sftTimeLog, sftModTime: begin
            CD := TDateTimePicker.Create(Scroll);
            CD.Kind := dtkDate;
            TimeLog.Value := GetInt64(pointer(aValue));
            CD.DateTime := TimeLog.ToDateTime;
          end;
          sftCreateTime:
            ; // is low-level read/only field by design
          sftBlob, sftMany:
            ; // not implemented yet               <------------------WHY here aValue IS EMPTY??

can you help me to understand?

Offline

#9 2013-06-25 15:42:13

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,187
Website

Re: create a TObjectList from TSQLRecordMany

... it is not implemented yet: a lookup field selection may be implemented later, e.g. via a sub form.

Offline

#10 2013-07-01 14:35:01

lele9
Member
Registered: 2011-10-28
Posts: 170

Re: create a TObjectList from TSQLRecordMany

yes i know that it is not implemented yet, i would like to implement but i can't understand how read the TSQLRecordMany instance by RTTI!
i try

case aFieldType of
          sftDateTime: begin
            CD := TDateTimePicker.Create(Scroll);
            CD.Kind := dtkDate;
            CD.DateTime := Iso8601ToDateTime(aValue);
          end;
          sftTimeLog, sftModTime: begin
            CD := TDateTimePicker.Create(Scroll);
            CD.Kind := dtkDate;
            TimeLog.Value := GetInt64(pointer(aValue));
            CD.DateTime := TimeLog.ToDateTime;
          end;
          sftCreateTime:
            ; // is low-level read/only field by design
          sftBlob, sftMany:
           begin
               obj := TSQLRecordMany(Pointer(aValue)); //but aValue = ''!!!!! WHY??
           end;

thanks,
Emanuele

Offline

Board footer

Powered by FluxBB