{Hint: save all files to location: C:\lamw\workspace\AppNiceProject1\jni }
unit unit1;
{$mode delphi}
interface
uses
Classes, SysUtils, AndroidWidget, Laz_And_Controls, tcpsocketclient;
type
{ TAndroidModule1 }
TAndroidModule1 = class(jForm)
jButton1: jButton;
jTCPSocketClient1: jTCPSocketClient;
jTextView1: jTextView;
procedure AndroidModule1Create(Sender: TObject);
procedure jButton1Click(Sender: TObject);
procedure jTCPSocketClient1BytesReceived(Sender: TObject;
var jbytesReceived: TDynArrayOfJByte);
procedure jTCPSocketClient1Connected(Sender: TObject);
private
{private declarations}
IsNewStuffCreated: boolean;
public
{public declarations}
jButtonRuntime: jButton;
jTCPSocketClientRuntime: jTCPSocketClient;
end;
var
AndroidModule1: TAndroidModule1;
implementation
{$R *.lfm}
{ TAndroidModule1 }
procedure TAndroidModule1.jButton1Click(Sender: TObject);
begin
if (Sender as jButton).Tag = 1 then
begin
if not IsNewStuffCreated then
begin
jButtonRuntime:= jButton.Create(Self); //pascal side button
jButtonRuntime.Tag:= 2;
jButtonRuntime.Text:= 'jButtonRuntime';
jButtonRuntime.LayoutParamWidth:= lpHalfOfParent;
jButtonRuntime.Anchor:= jButton1;
jButtonRuntime.PosRelativeToAnchor:= [raBelow];
jButtonRuntime.PosRelativeToParent:= [rpCenterHorizontal];
jButtonRuntime.OnClick:= jButton1Click; //delphi mode...
jButtonRuntime.Init(gApp); //java side button
jTCPSocketClientRuntime:= jTCPSocketClient.Create(Self);
jTCPSocketClientRuntime.Tag:= 2;
jTCPSocketClientRuntime.OnConnected:= jTCPSocketClient1Connected;
jTCPSocketClientRuntime.OnBytesReceived:= jTCPSocketClient1BytesReceived;
jTCPSocketClientRuntime.Init(gApp);
IsNewStuffCreated:= True; // <-----
end
else
begin
ShowMessage('Warning: jButtonRuntime was created!');
end;
end;
if (Sender as jButton).Tag = 2 then
begin
ShowMessage('Hello from created jButtonRuntime !!!');
end;
end;
procedure TAndroidModule1.jTCPSocketClient1BytesReceived(Sender: TObject;
var jbytesReceived: TDynArrayOfJByte);
begin
if (Sender as jTCPSocketClient).Tag = 1 then
begin
end;
if (Sender as jTCPSocketClient).Tag = 2 then
begin
end;
end;
procedure TAndroidModule1.jTCPSocketClient1Connected(Sender: TObject);
begin
if (Sender as jTCPSocketClient).Tag = 1 then
begin
end;
if (Sender as jTCPSocketClient).Tag = 2 then
begin
end;
end;
procedure TAndroidModule1.AndroidModule1Create(Sender: TObject);
begin
jButton1.Tag:= 1;
jTCPSocketClient1.Tag:= 1;
IsNewStuffCreated:= False;
end;
end.