fabriciocolombo / delphi-rest-client-api

A Delphi REST client API to consume REST services written in any programming language.
Apache License 2.0
380 stars 182 forks source link

Arrays in Class #80

Closed Tuldi closed 7 years ago

Tuldi commented 7 years ago

Hello!

I think I got an easy question:

I am using the get-Method right now.. i call the function two times... at first i got a jsonString which looks like this:

{ "ImmobilieId":1234, "Titel":"Garconniere Nähe Veterinäruni sucht neuen Mieter", "Bilder":[{ "BildId":12874,"Url":"http://**_/100249020160317.jpg"}, { "BildId":12875,"Url":"http://**_/97688920160111.jpg"}, { "BildId":12876 "Url":"http://***/97688820160111.jpg"} ] }

then i wrote these classes:

the classes:

` TjsonBild = class private FBildId : integer; FUrl : String; public property BildId : integer read FBildId write FBildId; property Url : String read FUrl write FUrl; end;

TjsonWebCrawler = class private FImmobilieId : integer; FTitel : String; FBilder : array of TjsonBild; function getBild(index : integer) : TjsonBild; public property ImmobilieId : integer read FImmobilieId write FImmobilieId; property Titel : String read FTitel write FTitel; property Bilder[index : integer] : TjsonBild read getbild; end;

implementation

function TjsonWebCrawler.getBild(index : integer) : TjsonBild;
begin
    result := self.FBilder[index];
end;

`

and now i try to call the get Function with the classes:

` procedure TFrmImmoAMetaFreigaben.btnGet2Click(Sender: TObject); var txt : string; foo : TjsonWebCrawler; begin inherited;

if globalRESTDatamodule = nil then begin Application.CreateForm(TdmRESTDataModule, globalRESTDatamodule); end;

txt := globalRESTDatamodule.myRestClient.Resource('http://172.19.31.138:5540/webcrawler/v1/api/immobilien/1234') .Accept(RestUtils.MediaType_Json) .Get;

foo := globalRESTDatamodule.myRestClient.Resource('http://172.19.31.138:5540/webcrawler/v1/api/immobilien/1234') .Accept(RestUtils.MediaType_Json) .Get;

ShowMessage('OK');

self.memo1.Text := foo.Titel + foo.Bilder[0].Url; end; `

But at the end of the function i get an error because foo.Bilder[0] seems to be nil!

Why is that? Do i have to declare the array differently, oder does this library not work with array in properties?

Thank you a thousand times!

greetings Tuldi

Tuldi commented 7 years ago

got it... TList<> is better than array ;-)