Oppure

Loading
27/02/14 8:28
zanzibar
Salve a tutti.
Sto scrivendo una classe in delphi per gestire un client rest che accede ai servizi di un webservice restful.La classe, che attualmente assegna solo gli endpoint del werbservice a delle proprietà, mi dà subito errore all'interno della procedura Create dove cerca di valorizzare la variabile privata flogonEndPoint:=value;
Immagino l'errore sia banale ma non capisco dove sta. Qualcuno mi può aiutare?
Ecco il codice:

unit Restclient;

interface

uses
Classes, SysUtils;

type

TRestClient = class
private
flogonEndPoint :string;
fauthorizationEndpoint :string;
ftokenEndpoint :string;
fconsoleEndpoint :string;
fmailstatisticsEndpoint :string;

procedure SetLogonEndPoint(value:string);
procedure SetAuthorizationEndPoint(value:string);
procedure SetTokenEndPoint(value:string);
procedure SetConsoleEndPoint(value:string);
procedure SetMailStatisticsEndPoint(value:string);

public
property logonEndpoint :string read flogonEndPoint write SetLogonEndPoint;
property authorizationEndpoint :string read fauthorizationEndPoint write SetAuthorizationEndPoint;
property tokenEndpoint :string read ftokenEndPoint write SetTokenEndPoint;
property consoleEndpoint :string read fconsoleEndPoint write SetConsoleEndPoint;
property mailstatisticsEndpoint:string read fmailstatisticsEndpoint write SetMailStatisticsEndPoint;

constructor Create;
destructor Destroy; override;

end;

implementation


constructor TRestClient.Create;
begin
SetLogonEndPoint('https://services/logon.....');
SetAuthorizationEndPoint('https://services/auth...');
SetTokenEndpoint('https://services/auth');
SetConsoleEndpoint('https://services/console');
SetMailstatisticsEndpoint('https://services/stats');

end;


procedure TRestClient.SetLogonEndPoint(value:string);
begin
flogonEndPoint:=value;
end;

procedure TRestClient.SetAuthorizationEndPoint(value:string) ;
begin
fauthorizationEndpoint:=value;
end;

procedure TRestClient.SetTokenEndPoint(value:string);
begin
ftokenEndpoint:=value;
end;

procedure TRestClient.SetConsoleEndPoint(value:string);
begin
fconsoleEndpoint:=value;
end;

procedure TRestClient.SetMailStatisticsEndPoint(value:string );
begin
fmailstatisticsEndpoint:=value;
end;


destructor TRestClient.Destroy;
begin

inherited;
end; 
aaa
27/02/14 12:43
Poggi Marco
Ciao!

Come hai stanziato un elemento di TRestClient ?
(In che modo accedi al costruttore ?)
aaa
27/02/14 13:20
zanzibar
Ciao a te!
Ho istanziato in questo modo:

var RSClient:TRestClient;
s:string;
begin

RSClient.Create;
s:=RSClient.logonEndpoint;
RSClient.Destroy;

end;
aaa
27/02/14 13:41
Poggi Marco
In Delphi una classe non può essere stanziata staticamente ( come i tipi nativi o record ), ma la si manipola attraverso un puntatore.
Quindi dovrai correggere in questo modo:
var  RSClient:TRestClient; 
      s:string; 
begin 

    RSClient:= TRestClient.create; // Creo un' iatanza di TRestClient, e assegno il suo indirizzo a RSClient.
    s:=RSClient.logonEndpoint; 
    RSClient.Destroy; 

end;


Tieni sempre presente questo particolare quando passi un' istanza di una classe ad un sottoprogramma.
aaa
28/02/14 9:19
zanzibar
Grazie Marco..
C'hai ragione..Mi sono persa in un bicchier d'acqua...
Con la correzione funziona.
aaa