I have Delphi lib which must return information read via socket.
function GetBufferInfo(Address: PChar): PChar; export; stdcall;
var
BD: TBufferData;
begin
BD := TBufferData.Create;
Result := PChar(TBufferData.GetData);
BD.Free;
end;
TBufferData class has a method ReadData which is being called when socket Read event fires. So it can be called several times until all info is read. The problem is how to wait while information is being read and don’t go out of GetBufferInfo method. I thought about threads but don’t know how exactly it can be done.
I created a small example which demonstrates the issue:
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils, Classes, Windows;
type
TBufferData = class
private
FResult: string;
public
constructor Create;
procedure ReadData(Sender: TObject; Buf: string; var Size: Integer);
function GetData: string;
end;
{ TBufferData }
var
BD: TBufferData;
s: string;
{ TBufferData }
constructor TBufferData.Create;
begin
FResult := 'Some text received via socket';
end;
function TBufferData.GetData: string;
begin
Result := FResult;
end;
procedure TBufferData.ReadData(Sender: TObject; Buf: string; var Size: Integer);
begin
//info is being received from socket
FResult := FResult + Buf;
end;
begin
BD := TBufferData.Create;
s := BD.GetData;
Writeln(s);
BD.Free;
Readln;
end.
Thanks in advance
Yura
Application.ProcessMessages for console would look like this. State flag will be set outside.