The server side, definition to the output of the classes and methods are as follows:
Type
{$MethodInfo ON}
TEmployeeVO=class (Tcomponent)
Private
Femployees: TObjectList
//function createEmployeeJsonObject (employee: Temployee) : string;
//function createEmployeeJsonArray: string;
The function createEmployeeJsonObjectJ (employee: Temployee) : TJsonobject;
Public
The function getEmployeeJ (const sName: string) : Tjsonobject;
The function getAllEmployeesJ: Tjsonarray;
Procedure addEmployee (const sName: string; Const sEmail: string; Const sPhone: string);
end;
{$MethodInfo OFF}
The getemployeeJ method implementation is as follows:
The function TEmployeeVO. GetEmployeeJ (const sName: string) : Tjsonobject;
Var
Ie: Tlist
Employee: Temployee;
The begin
Result:=nil;
Ie:=Femployees. GetEnumerator;
While (ie. MoveNext) do
The begin
Employee:=ie. Current;
If the employee. The Name=sName then
The begin
Result:=createEmployeeJsonObjectJ (employee);
break;
end;
end;
end;
The function TEmployeeVO. CreateEmployeeJsonObjectJ (
Employee: Temployee) : TJsonobject;
Var
Ajo: Tjsonobject;
The begin
Ajo:=Tjsonobject. Create;
Ajo. AddPair (' Name ', the employee Name);
Ajo. AddPair (' Email ', the employee Email);
Ajo. AddPair (' Phone 'employee. Phone);
Result:=ajo;
end;
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
The client has a new staff, staff query button, new features no error, query the total error, the code is as follows:
Procedure TForm2. Button2Click (Sender: TObject);
Var evo: TEmployeeVOClient;
Jo: Tjsonobject;
Employee: Temployee;
The begin
Mr:=TEmployeeVOClient. Create (self. SQLConnection1. DBXConnection);
Jo:=evo getEmployeeJ (edit4. Text);
If jo<> Nil then
The begin
Employee:=Temployee. Create (Jo. Get (0)) jsonvalue) value,
Jo. Get (1). Jsonvalue. Value, Jo. Get (2) jsonvalue. Value);
Edit5. Text:=employee. Email;
Edit6. Text:=the employee. The Phone;
Freeandnil (Jo);
The end;
Freeandnil (employee);
The evo. Free;
end;
Question:
1. The client is running, I won't increase staff, contact point direct employees, the program runs to Jo:=evo. GetEmployeeJ (edit4. Text); An error, I think it's caused by the return value is nil getEmployeeJ, how to change? Another getEmployeeJ returns tjsonobject, equivalent to a pointer, but the client and the server is not in a memory space, to the client the pointer what is the point?
2. If after adding staff query again, press f8 to execute, debugging information display can be achieved when querying data, can perform to the end, but did not finish, when I press f8 continue to jump to other system code, finally in procedure TApplication. Run; This, again and again in the following segments:
Repeat
Try
HandleMessage;
Except,
HandleException (Self);
end;
Until Terminated;
According to a lot of time, patience, direct f9 to quit, returned to the main interface, everything is normal,
3. The application of hierarchical structure, employee data is the server? But when I turned off the client side, then open the query, display an error, I don't think should be can query to the data, is it the client closed, server-side data is empty?
4. I want to perform the client increase after add employees, increase the server-side data how to display? With what method?
CodePudding user response: