Download - Trik n Tips Delphi 7
Trik Database1. Menambahkan No Pada DB GRID
1. create new blank field in dbgrid 2. rename the title with 'No:' 3. put this code in OnDrawColumncell 4. Now your Grid has a row number procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin if DataSource1.DataSet.RecNo > 0 then begin if Column.Title.Caption = 'No:' then DBGrid1.Canvas.TextOut(Rect.Left + 2, Rect.Top, IntToStr(DataSource1.DataSet.RecNo)); end; end;
2. Memilih semua Field pada DBGRIDfunction GridSelectAll(Grid: TDBGrid): Longint; begin Result := 0; Grid.SelectedRows.Clear; with Grid.DataSource.DataSet do begin First; DisableControls; try while not EOF do begin Grid.SelectedRows.CurrentRowSelected := True; Inc(Result); Next; end; finally EnableControls; end; end; end; procedure TForm1.Button1Click(Sender: TObject); begin GridSelectAll(DBGrid1); end;
3. Random Field pada DBGRIDprocedure TForm1.Button1Click(Sender: TObject); begin Randomize;
Table1.First; Table1.MoveBy(Random(Table1.RecordCount)); end;
4. Membuat warna DBGRIDprocedure TForm1.ColorGrid(dbgIn: TDBGrid; qryIn: TQuery; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var iValue: LongInt; begin if (DataCol = 0) then begin iValue := qryIn.FieldByName('HINWEIS_COLOR').AsInteger; case iValue of 1: dbgIn.Canvas.Brush.Color := clGreen; 2: dbgIn.Canvas.Brush.Color := clLime; 3: dbgIn.Canvas.Brush.Color := clYellow; 4: dbgIn.Canvas.Brush.Color := clRed; end; dbgIn.DefaultDrawColumnCell(Rect, DataCol, Column, State); end; end; procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin ColorGrid(DBGrid1, Query1, Rect, DataCol, Column, State); end;
Internet & LAN1. Send a file from a TServerSocket to a TClientSocket
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ScktComp, StdCtrls; type TForm1 = class(TForm) ClientSocket1: TClientSocket; ServerSocket1: TServerSocket; btnTestSockets: TButton; procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure ClientSocket1Disconnect(Sender: TObject; Socket: TCustomWinSocket);
procedure ClientSocket1Connect(Sender: TObject; Socket: TCustomWinSocket); procedure ServerSocket1ClientConnect(Sender: TObject; Socket: TCustomWinSocket); procedure btnTestSocketsClick(Sender: TObject); private FStream: TFileStream; { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket); var iLen: Integer; Bfr: Pointer; begin iLen := Socket.ReceiveLength; GetMem(Bfr, iLen); try Socket.ReceiveBuf(Bfr^, iLen); FStream.Write(Bfr^, iLen); finally FreeMem(Bfr); end; end; procedure TForm1.FormCreate(Sender: TObject); begin FStream := nil; end; procedure TForm1.FormDestroy(Sender: TObject); begin if Assigned(FStream) then begin FStream.Free; FStream := nil; end; end; procedure TForm1.ClientSocket1Disconnect(Sender: TObject; Socket: TCustomWinSocket); begin
if Assigned(FStream) then begin FStream.Free; FStream := nil; end; end; procedure TForm1.ClientSocket1Connect(Sender: TObject; Socket: TCustomWinSocket); begin FStream := TFileStream.Create('c:\temp\test.stream.html', fmCreate or fmShareDenyWrite); end; procedure TForm1.ServerSocket1ClientConnect(Sender: TObject; Socket: TCustomWinSocket); begin Socket.SendStream(TFileStream.Create('c:\temp\test.html', fmOpenRead or fmShareDenyWrite)); end; procedure TForm1.btnTestSocketsClick(Sender: TObject); begin ServerSocket1.Active := True; ClientSocket1.Active := True; end; end.
2. Implementasi web server dan Klienunit convertImpl;interfaceuses sysutils, adodb, InvokeRegistry, Types, XSBuiltIns, convertIntf;type { Tconvert } Tconvert = class(TInvokableClass, Iconvert) public function test(i: Integer): string; stdcall; function login(uid: string; pass: string): Boolean; stdcall; function drugmg(drugid: Integer): string; stdcall; function drugmt(drugid: Integer): string; stdcall; function drugsh(drugid: Integer): string; stdcall; function drugcod(drugid: Integer): string; stdcall; function druggb(drugid: Integer): string; stdcall; function drugho(drugid: Integer): string; stdcall; function drugmo(drugid: Integer): string; stdcall; function drugma(drugid: Integer): string; stdcall; function drugotc(drugid: Integer): string; stdcall; function drugotc_msg(drugid: Integer): string; stdcall; function drugtedp(drugid: Integer): string; stdcall; function drughsef(drugid: Integer): string; stdcall;
function druggkh(drugid: Integer): string; stdcall; function druggfo(drugid: Integer): string; stdcall; function drugosef(drugid: Integer): string; stdcall; function drugvcod(drugid: Integer): string; stdcall; function drugmot1(drugid: Integer): string; stdcall; function drugmot2(drugid: Integer): string; stdcall; function drugjay1(drugid: Integer): string; stdcall; function drugjay2(drugid: Integer): string; stdcall; function drugtad1(drugid: Integer): string; stdcall; function drugtad2(drugid: Integer): string; stdcall; function drugtad3(drugid: Integer): string; stdcall; function drugtad4(drugid: Integer): string; stdcall; function drugtadmsg(drugid: Integer): string; stdcall; function drugfn(drugid: Integer): string; stdcall; function drugdoz(drugid: Integer): string; stdcall; function drugdas(drugid: Integer): string; stdcall; function drugtmp(drugid: Integer): string; stdcall; function druglastchange(drugid: Integer): string; stdcall; function drugrundat(drugid: Integer): string; stdcall; function drugchanger(drugid: Integer): string; stdcall; function drugnewpr(drugid: Integer): string; stdcall; function druglist(): string; stdcall; function currusernam(uid: string): string; stdcall; function curruserfam(uid: string): string; stdcall; function curruserlimit(uid: string): string; stdcall; function curruseraddr(uid: string): string; stdcall; function currusertel(uid: string): string; stdcall; function druginsert(values: string): Boolean; stdcall; function drugupdate(drugid: Integer; values: string): Boolean; stdcall; function drugdelete(drugid: Integer; values: string): Boolean; stdcall; function LOGINinsert(values: string): Boolean; stdcall; function LOGINupdate(drugid: Integer; values: string): Boolean; stdcall; function LOGINdelete(drugid: Integer; values: string): Boolean; stdcall; end;implementationfunction Tconvert.LOGINupdate(drugid: Integer; values: string): Boolean;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data';
conn.LoginPrompt := False; conn.Connected := True; except Result := False; end; try tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.Connection.BeginTrans; tmp.SQL.Clear; tmp.SQL.Add('UPDATE LOGIN SET ' + VALUES + ' WHERE UID=''' + IntToStr(DRUGID) + ''''); tmp.ExecSQL; tmp.Connection.CommitTrans; Result := True; except begin TMP.Connection.RollbackTrans; Result := False; end;//EXCEPT tmp.Free; conn.Connected := False; conn.Free; end;//TRYend;//insertfuncfunction Tconvert.drugupdate(drugid: Integer; values: string): Boolean;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := False; end; try tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.Connection.BeginTrans; tmp.SQL.Clear; tmp.SQL.Add('UPDATE drug SET ' + VALUES + ' WHERE DRUGID=''' + IntToStr(DRUGID) + '''');
tmp.ExecSQL; tmp.Connection.CommitTrans; Result := True; except begin TMP.Connection.RollbackTrans; Result := False; end;//EXCEPT tmp.Free; conn.Connected := False; conn.Free; end;//TRYend;//insertfuncfunction Tconvert.drugdelete(drugid: Integer; values: string): Boolean;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := False; end; try tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.Connection.BeginTrans; tmp.SQL.Clear; tmp.SQL.Add('DELETE FROM drug WHERE DRUGID=''' + IntToStr(DRUGID) + ''''); tmp.ExecSQL; tmp.Connection.CommitTrans; Result := True; except begin TMP.Connection.RollbackTrans; Result := False; end;//EXCEPT tmp.Free; conn.Connected := False; conn.Free;
end;//TRYend;//insertfuncfunction Tconvert.LOGINdelete(drugid: Integer; values: string): Boolean;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := False; end; try tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.Connection.BeginTrans; tmp.SQL.Clear; tmp.SQL.Add('DELETE FROM LOGIN WHERE DRUGID=''' + IntToStr(DRUGID) + ''''); tmp.ExecSQL; tmp.Connection.CommitTrans; Result := True; except begin TMP.Connection.RollbackTrans; Result := False; end;//EXCEPT tmp.Free; conn.Connected := False; conn.Free; end;//TRYend;//insertfuncfunction Tconvert.druginsert(values: string): Boolean;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Ca
talog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := False; end; try tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.Connection.BeginTrans; tmp.SQL.Clear; tmp.SQL.Add('insert into drug values(' + values + ')'); tmp.ExecSQL; tmp.Connection.CommitTrans; Result := True; except begin TMP.Connection.RollbackTrans; Result := False; end;//EXCEPT tmp.Free; conn.Connected := False; conn.Free; end;//TRYend;//insertfuncfunction Tconvert.LOGINinsert(values: string): Boolean;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := False; end; try tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.Connection.BeginTrans; tmp.SQL.Clear;
tmp.SQL.Add('insert into LOGIN values(' + values + ')'); tmp.ExecSQL; tmp.Connection.CommitTrans; Result := True; except begin TMP.Connection.RollbackTrans; Result := False; end;//EXCEPT tmp.Free; conn.Connected := False; conn.Free; end;//TRYend;//insertfuncfunction Tconvert.curruseraddr(uid: string): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select addr from login where (uid=N''' + uid + ''')'); tmp.ExecSQL; tmp.Open; Result := tmp.FieldByName('addr').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;//funcfunction Tconvert.currusertel(uid: string): string;var conn: tadoconnection; tmp: tadoquery;
begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select tel from login where (uid=N''' + uid + ''')'); tmp.ExecSQL; tmp.Open; Result := tmp.FieldByName('tel').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;//funcfunction Tconvert.curruserlimit(uid: string): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select limit from login where (uid=N''' + uid + ''')'); tmp.ExecSQL; tmp.Open; Result := tmp.FieldByName('limit').AsString;
tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;//funcfunction Tconvert.curruserfam(uid: string): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select fam from login where (uid=N''' + uid + ''')'); tmp.ExecSQL; tmp.Open; Result := tmp.FieldByName('fam').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;//funcfunction Tconvert.currusernam(uid: string): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except
Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select nam from login where (uid=N''' + uid + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not found!' else Result := tmp.FieldByName('nam').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;//funcfunction tconvert.druglist(): string;var conn: tadoconnection; tmp: tadoquery; x: string;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select drugid from drug '); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else begin tmp.First; x := ''; while not tmp.EOF do begin
x := x + tmp.FieldByName('drugid').AsString; tmp.Next; end; Result := x; end;//if tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugtmp(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select tmp from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('tmp').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.druglastchange(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try
conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select lastchange from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('lastchange').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugchanger(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select changer from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!'
else Result := tmp.FieldByName('changer').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugrundat(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select rundat from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('rundat').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugnewpr(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Ca
talog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select newpr from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('newpr').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugdas(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select das from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('das').AsString; tmp.Close;
tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugdoz(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select doz from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('doz').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugfn(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True;
except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select fn from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('fn').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugtadmsg(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select tadmsg from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('tadmsg').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;
end;function tconvert.drugtad4(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select tad4 from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('tad4').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugtad3(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end;
tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select tad3 from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('tad3').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugtad2(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select tad2 from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('tad2').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugtad1(drugid: Integer): string;var
conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select tad1 from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('tad1').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugjay2(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear;
tmp.SQL.Add('select jay2 from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('jay2').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugjay1(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select jay1 from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('jay1').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugmot2(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin
try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select mot2 from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('mot2').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugmot1(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select mot1 from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open;
if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('mot1').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugvcod(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select vcod from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('vcod').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugosef(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString :=
'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select osef from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('osef').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.druggfo(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select gfo from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('gfo').AsString;
tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.druggkh(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select gkh from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('gkh').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drughsef(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False;
conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select hsef from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('hsef').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugtedp(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select tedp from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('tedp').AsString; tmp.Close; tmp.Free; conn.Connected := False;
conn.Free;end;function tconvert.drugotc_msg(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select otc_msg from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('otc_msg').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugotc(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!';
end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select otc from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('otc').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugma(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select ma from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('ma').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugmo(drugid: Integer): string;
var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select mo from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('mo').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugho(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn;
tmp.SQL.Clear; tmp.SQL.Add('select ho from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('ho').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.druggb(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select gb from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('gb').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugcod(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;
begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select cod from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('cod').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugsh(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select sh from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL;
tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('sh').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugmt(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select mt from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('mt').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.drugmg(drugid: Integer): string;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil);
conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := 'Faild connection!'; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select mg from drug where (drugid=N''' + IntToStr(drugid) + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := 'Not Found!' else Result := tmp.FieldByName('mg').AsString; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.login(uid: string; pass: string): Boolean;var conn: tadoconnection; tmp: tadoquery;begin try conn := tadoconnection.Create(nil); conn.ConnectionString := 'Provider=SQLOLEDB.1;Password=z200t68i;Persist Security Info=True;User ID=irdrug;Initial Catalog=irdrug_data'; conn.LoginPrompt := False; conn.Connected := True; except Result := False; end; tmp := tadoquery.Create(nil); tmp.Connection := conn; tmp.SQL.Clear; tmp.SQL.Add('select * from login where (uid=N''' + uid + ''') and (password=N''' + pass + ''')'); tmp.ExecSQL; tmp.Open; if tmp.IsEmpty then Result := False
else Result := True; tmp.Close; tmp.Free; conn.Connected := False; conn.Free;end;function tconvert.test(i: Integer): string;begin case i of 0: Result := 'Zero'; 1: Result := 'one'; 2: Result := 'two'; 3: Result := 'three'; 4: Result := 'four'; 5: Result := 'five'; 6: Result := 'six'; 7: Result := 'seven'; 8: Result := 'eight'; 9: Result := 'nine'; else Result := 'out of range'; end;end;initialization { Invokable classes must be registered } InvRegistry.RegisterInvokableClass(Tconvert);end.{####################################################################}{ Invokable interface Iconvert }{####################################################################}unit convertIntf;interfaceuses InvokeRegistry, Types, XSBuiltIns;type { Invokable interfaces must derive from IInvokable } Iconvert = interface(IInvokable) ['{9AC31ECA-37C4-42C2-9E9D-1E0117A8C746}'] function test(i: Integer): string; stdcall; function login(uid: string; pass: string): Boolean; stdcall; function drugmg(drugid: Integer): string; stdcall; function drugmt(drugid: Integer): string; stdcall; function drugsh(drugid: Integer): string; stdcall; function drugcod(drugid: Integer): string; stdcall; function druggb(drugid: Integer): string; stdcall;
function drugho(drugid: Integer): string; stdcall; function drugmo(drugid: Integer): string; stdcall; function drugma(drugid: Integer): string; stdcall; function drugotc(drugid: Integer): string; stdcall; function drugotc_msg(drugid: Integer): string; stdcall; function drugtedp(drugid: Integer): string; stdcall; function drughsef(drugid: Integer): string; stdcall; function druggkh(drugid: Integer): string; stdcall; function druggfo(drugid: Integer): string; stdcall; function drugosef(drugid: Integer): string; stdcall; function drugvcod(drugid: Integer): string; stdcall; function drugmot1(drugid: Integer): string; stdcall; function drugmot2(drugid: Integer): string; stdcall; function drugjay1(drugid: Integer): string; stdcall; function drugjay2(drugid: Integer): string; stdcall; function drugtad1(drugid: Integer): string; stdcall; function drugtad2(drugid: Integer): string; stdcall; function drugtad3(drugid: Integer): string; stdcall; function drugtad4(drugid: Integer): string; stdcall; function drugtadmsg(drugid: Integer): string; stdcall; function drugfn(drugid: Integer): string; stdcall; function drugdoz(drugid: Integer): string; stdcall; function drugdas(drugid: Integer): string; stdcall; function drugtmp(drugid: Integer): string; stdcall; function druglastchange(drugid: Integer): string; stdcall; function drugrundat(drugid: Integer): string; stdcall; function drugchanger(drugid: Integer): string; stdcall; function drugnewpr(drugid: Integer): string; stdcall; function druglist(): string; stdcall; //list koliye drug id ha function currusernam(uid: string): string; stdcall; function curruserfam(uid: string): string; stdcall; function curruserlimit(uid: string): string; stdcall; function curruseraddr(uid: string): string; stdcall; function currusertel(uid: string): string; stdcall; function druginsert(values: string): Boolean; stdcall; function drugupdate(drugid: Integer; values: string): Boolean; stdcall; function drugdelete(drugid: Integer; values: string): Boolean; stdcall; function LOGINinsert(values: string): Boolean; stdcall; function LOGINupdate(drugid: Integer; values: string): Boolean; stdcall; function LOGINdelete(drugid: Integer; values: string): Boolean; stdcall; { Methods of Invokable interface must not use the default } { calling convention; stdcall is recommended } end;implementationinitialization
{ Invokable interfaces must be registered } InvRegistry.RegisterInterface(TypeInfo(Iconvert));end.{####################################################################}{ SOAP WebModule }{####################################################################}unit Unit1;interfaceuses SysUtils, Classes, HTTPApp, InvokeRegistry, WSDLIntf, TypInfo, WebServExp, WSDLBind, XMLSchema, WSDLPub, SOAPPasInv, SOAPHTTPPasInv, SOAPHTTPDisp, WebBrokerSOAP;type TWebModule1 = class(TWebModule) HTTPSoapDispatcher1: THTTPSoapDispatcher; HTTPSoapPascalInvoker1: THTTPSoapPascalInvoker; WSDLHTMLPublish1: TWSDLHTMLPublish; procedure WebModule1DefaultHandlerAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean); private { Private declarations } public { Public declarations } end;var WebModule1: TWebModule1;implementation{$R *.dfm}procedure TWebModule1.WebModule1DefaultHandlerAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);begin WSDLHTMLPublish1.ServiceInfo(Sender, Request, Response, Handled);end;end.{####################################################################}unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, InvokeRegistry, StdCtrls, Rio, SOAPHTTPClient;type TForm1 = class(TForm) HTTPRIO1: THTTPRIO; Edit2: TEdit; Edit3: TEdit;
Label2: TLabel; Label3: TLabel; Button2: TButton; Label4: TLabel; procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementationuses convertIntf, mainmenu;{$R *.dfm}procedure TForm1.Button2Click(Sender: TObject);var temp: iconvert; i: Integer;begin Form1.Visible := False; temp := httprio1 as iconvert; if temp.login(edit2.Text, edit3.Text) then label4.Caption := 'Login' else label4.Caption := 'Failed!'; // 1->admin 2-> change drug,chage curr,insert drug,change price 3->iuser,uuser,current 4->change current i := StrToInt(temp.curruserlimit(edit2.Text)); FORM2.Label1.Caption := temp.currusernam(edit2.Text); FORM2.Label2.Caption := temp.curruserfam(edit2.Text); FORM2.Label3.Caption := temp.curruseraddr(edit2.Text); FORM2.Label4.Caption := temp.currusertel(edit2.Text); case i of 1: begin form2.iuser.Enabled := True; form2.uuser.Enabled := True; form2.curruser.Enabled := True; form2.udrug.Enabled := True; form2.idrug.Enabled := True; form2.rundat.Enabled := True; form2.Button7.Enabled := True; form2.Show; end;
2: begin form2.iuser.Enabled := False; form2.uuser.Enabled := False; form2.curruser.Enabled := True; form2.udrug.Enabled := True; form2.idrug.Enabled := True; form2.rundat.Enabled := True; form2.Button7.Enabled := True; form2.Show; end; 3: begin form2.iuser.Enabled := True; form2.uuser.Enabled := True; form2.curruser.Enabled := True; form2.udrug.Enabled := False; form2.idrug.Enabled := False; form2.rundat.Enabled := False; form2.Button7.Enabled := True; form2.Show; end; 4: begin form2.iuser.Enabled := False; form2.uuser.Enabled := False; form2.curruser.Enabled := True; form2.udrug.Enabled := False; form2.idrug.Enabled := False; form2.rundat.Enabled := False; form2.Button7.Enabled := True; form2.Show; end; else begin ShowMessage('Access Denided!'); halt; end; end;//caseend;end.{####################################################################}unit adduser;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, InvokeRegistry, Rio, SOAPHTTPClient;type TForm3 = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Edit5: TEdit; Edit6: TEdit; ComboBox1: TComboBox; Edit7: TEdit; Button1: TButton; Button2: TButton; HTTPRIO1: THTTPRIO; procedure Button1Click(Sender: TObject); procedure Edit1Change(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form3: TForm3;implementationuses convertIntf;{$R *.dfm}procedure TForm3.Button1Click(Sender: TObject);var temp: iconvert;begin temp := httprio1 as iconvert; if temp.currusernam(edit1.Text) = 'Not found!' then button2.Enabled := True else button2.Enabled := False;end;
procedure TForm3.Edit1Change(Sender: TObject);begin button2.Enabled := False; button1.Enabled := True;end;procedure TForm3.Button2Click(Sender: TObject);var temp: iconvert; s: string;begin temp := httprio1 as iconvert; s := ' N''' + edit1.Text + ''',N''' + edit2.Text + ''',' + IntToStr(combobox1.ItemIndex) + ',N''' + edit3.Text + ''',N''' + edit4.Text + ''',N''' + edit5.Text + ''',N''' + edit6.Text + ''',' + edit7.Text + ' '; if temp.LOGINinsert(s) then begin ShowMessage('saved'); edit1.Text := ''; edit2.Text := ''; edit3.Text := ''; edit4.Text := ''; edit5.Text := ''; edit6.Text := ''; edit7.Text := ''; combobox1.ItemIndex := 0; button2.Enabled := False; end else begin ShowMessage('Not saved!'); button2.Enabled := False; end;end;end.
3. Chat menggunakan TCP CLIENT/SERVERunit TcpConnection;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Sockets;type ...Host1: TEdit; RPort: TEdit; LPort: TEdit;
Lines1: TEdit; ChatWnd: TMemo; ......TcpClient1: TTcpClient; TcpServer1: TTcpServer;procedure Connect1Click(Sender: TObject);procedure Send1Click(Sender: TObject);procedure TcpServer1Accept(Sender: TObject; ClientSocket: TCustomIpClient); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Connect1Click(Sender: TObject);begin TcpServer1.Active := False; {Disconnect First} TcpServer1.LocalPort := LPort.Text; TcpServer1.Active := True; {Then Connect}end;procedure TForm1.Send1Click(Sender: TObject);begin TcpClient1.RemoteHost := Host1.Text; {To connect to Server you must know his IP address, like 255.255.255.255} TcpClient1.RemotePort := RPort.Text; try if TcpClient1.Connect then TcpClient1.Sendln(Lines1.Text); finally TcpClient1.Disconnect; end;end;{OnAccept Event}procedure TForm1.TcpServer1Accept(Sender: TObject; ClientSocket: TCustomIpClient);var s: string;begin ChatWnd.Lines.Add('Start Sending Data'); ChatWnd.Lines.Add('Rem Host: ' + ClientSocket.LookupHostName(ClientSocket.RemoteHost) + ' (' + ClientSocket.RemoteHost + ')');
s := ClientSocket.Receiveln; while s <> '' do begin ChatWnd.Lines.Add(s); s := ClientSocket.Receiveln; end; ChatWnd.Lines.Add('End Sending Data');end;end.
4. Register sendiri Protocol (TCP){+++ German: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Hallo alle zusammen,ich möchte euch zeigen, wie man eigene Protokolle registriert. (bzw. löscht)Wir schreiben dazu unser Protokoll in die Registry.+++ English: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++Hello all together,I want to show you how to register own protocols. (and deleting)We will write our protocol into the registry.}{+++ German: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Diese Procedur öffnet die Registry und schreibt folgendes rein: HKEY_CLASSES_ROOT +NAME (STANDARD) URL:NAME (ERKLÄRUNG) EditFlags 2 Source Filter [leer] URL Protocol [leer] +SHELL +OPEN +COMMAND (STANDARD) ExecuteStrDer ExecuteStr sollte irgendwo %1 enthalten, da an dieser Stelle der Shellbefehl angegeben wird.BSP:NAME: Chat;Describtion: Chatprotokoll;ExecuteStr: "C:\ChatClient.exe %1".Chat://2002/ -> Führt "C:\Chatclient.exe Chat://2002/" aus.+++ English: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++This procedure opens the registry ein write the following into it. HKEY_CLASSES_ROOT +NAME (DEFAULT) URL:NAME (Describtion) EditFlags 2 Source Filter [empty] URL Protocol [empty] +SHELL +OPEN
+COMMAND (DEFAULT) ExecuteStrThe ExecuteStr should include somewhere %1 because at this position the shell-order will be included.Example:NAME: Chat;Describtion: Chatprotocol;ExecuteStr: "C:\ChatClient.exe %1".Chat://2002/ -> executes: "C:\Chatclient.exe Chat://2002/"}
procedure RegisterProtocol(const Name, Describtion, ExecuteStr: string);var reg: TRegistry;begin reg := TRegistry.Create; try reg.RootKey := HKEY_CLASSES_ROOT; reg.OpenKey(Name, True); try reg.Writestring('', 'URL:' + Name +' (' + Describtion + ')'); reg.WriteInteger('EditFlags', 2); reg.WriteString('Source Filter', ''); reg.WriteString('URL Protocol', ''); reg.OpenKey('shell', True); reg.OpenKey('open', True); reg.OpenKey('command', True); reg.Writestring('', ExecuteStr); finally reg.CloseKey; end; finally reg.Free; end;end;{+++ German: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Diese Prozedur ermöglich das Löschen eines Protokolls.Vorsicht: AUCH HTTP FTP HTTPS können gelöscht werden!!!+++ English: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++This procedure allows you to delete a protocol again.Attention: HTTP FTP HTTPS can also be deleted.}procedure UnregisterProtocol(const Name: string);var reg: TRegistry;begin
reg := TRegistry.Create; try reg.RootKey := HKEY_CLASSES_ROOT; reg.DeleteKey(Name); finally reg.Free; end;end;{+++ German: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Ein kleines Beispiel soll die Verwendung zeigen.Wir registrieren das Chatprotokoll und lesen die ParamStr aus.Nach dem registrieren gehen sie Start|Ausführen und geben sie "CHAT://OnlyaTest" ein.Danach klicken sie Button2 um das Protokoll wieder zu löschen.+++ English: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++A little example shall illustrate the using.We register the "chatprotocol" and read the ParamStr.After the registering you should go START|EXECUTE and enter "Chat://OnlyAText".After that you should click button2 to delete the protocol again.Komponenten / components:Memo1: TMemo;Button1: TButton;Button2: TButton;}procedure TForm1.Button1Click(Sender: TObject);var Name, Describtion, Executestr: string;begin Name := 'CHAT'; Describtion := 'BSN CHAT SERVER'; ExecuteStr := Application.ExeName + '%1'; RegisterProtocol(Name, Describtion, ExecuteStr);end;procedure TForm1.Button2Click(Sender: TObject);begin UnRegisterProtocol('CHAT');end;procedure TForm1.FormCreate(Sender: TObject);var i: Integer;begin for i := 0 to PARAMCOUNT do Memo1.Lines.Add(ParamStr(i));end;
5. get the name of the local file that is being cached?uses WiniNet;// Get Cached File Path From URLfunction GetCachedFileFromURL(strUL: string; var strLocalFile: string): boolean;var lpEntryInfo: PInternetCacheEntryInfo; hCacheDir: LongWord; dwEntrySize: LongWord; dwLastError: LongWord;begin Result := False; dwEntrySize := 0; // Begin the enumeration of the Internet cache. FindFirstUrlCacheEntry(nil, TInternetCacheEntryInfo(nil^), dwEntrySize); GetMem(lpEntryInfo, dwEntrySize); hCacheDir := FindFirstUrlCacheEntry(nil, lpEntryInfo^, dwEntrySize); if (hCacheDir <> 0) and (strUL = lpEntryInfo^.lpszSourceUrlName) then begin strLocalFile := lpEntryInfo^.lpszLocalFileName; Result := True; end; FreeMem(lpEntryInfo); if Result = False then repeat dwEntrySize := 0; // Retrieves the next cache group in a cache group enumeration FindNextUrlCacheEntry(hCacheDir, TInternetCacheEntryInfo(nil^), dwEntrySize); dwLastError := GetLastError(); if (GetLastError = ERROR_INSUFFICIENT_BUFFER) then begin GetMem(lpEntryInfo, dwEntrySize); if (FindNextUrlCacheEntry(hCacheDir, lpEntryInfo^, dwEntrySize)) then begin if strUL = lpEntryInfo^.lpszSourceUrlName then begin strLocalFile := lpEntryInfo^.lpszLocalFileName; Result := True; Break; end; end; FreeMem(lpEntryInfo); end; until (dwLastError = ERROR_NO_MORE_ITEMS);end;
6. ShutDown komputer melalui jaringanunit shutdown;interfaceuses Windows, StdCtrls;procedure shut(system, nachricht: string; force, reboot: Boolean; countdown: Integer);procedure abortshut(system: string);implementationconst SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';var hdlg: DWORD = 0;procedure shut(system, nachricht: string; force, reboot: Boolean; countdown: Integer);var otoken, hToken: THandle; tp: TTokenPrivileges; h: DWORD;begin OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES, hToken); otoken := htoken; LookupPrivilegeValue(nil, SE_SHUTDOWN_NAME, tp.Privileges[0].luid); tp.privilegecount := 1; tp.privileges[0].Attributes := SE_PRIVILEGE_ENABLED; h := 0; AdjustTokenPrivileges(hToken, False, tp, 0, PTokenPrivileges(nil)^, h); InitiateSystemShutdown(PChar(system), PChar(nachricht), countdown, force, reboot); tp.privilegecount := 1; tp.privileges[0].Attributes := SE_PRIVILEGE_ENABLED; h := 0; AdjustTokenPrivileges(oToken, False, tp, 0, PTokenPrivileges(nil)^, h); CloseHandle(hToken);end;procedure abortshut(system: string);var hToken: THandle; tp: TTokenPrivileges; h: DWORD;begin OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES, hToken); LookupPrivilegeValue(PChar(system), SE_SHUTDOWN_NAME, tp.Privileges[0].luid); tp.privilegecount := 1; tp.privileges[0].Attributes := SE_PRIVILEGE_ENABLED; h := 0; AdjustTokenPrivileges(hToken, False, tp, 0, PTokenPrivileges(nil)^, h);
CloseHandle(hToken); abortSystemShutdown(PChar(system));end;end.
7. get the list of active process on a PC of my network?unit PerfInfo;interfaceuses Windows, SysUtils, Classes;type TPerfCounter = record Counter: Integer; Value: TLargeInteger; end; TPerfCounters = Array of TPerfCounter; TPerfInstance = class private FName: string; FCounters: TPerfCounters; public property Name: string read FName; property Counters: TPerfCounters read FCounters; end; TPerfObject = class private FList: TList; FObjectID: DWORD; FMachine: string; function GetCount: Integer; function GetInstance(Index: Integer): TPerfInstance; procedure ReadInstances; public property ObjectID: DWORD read FObjectID; property Item[Index: Integer]: TPerfInstance read GetInstance; default; property Count: Integer read GetCount; constructor Create(const AMachine: string; AObjectID: DWORD); destructor Destroy; override; end;procedure GetProcesses(const Machine: string; List: TStrings);implementationtype PPerfDataBlock = ^TPerfDataBlock; TPerfDataBlock = record Signature: array[0..3] of WCHAR;
LittleEndian: DWORD; Version: DWORD; Revision: DWORD; TotalByteLength: DWORD; HeaderLength: DWORD; NumObjectTypes: DWORD; DefaultObject: Longint; SystemTime: TSystemTime; PerfTime: TLargeInteger; PerfFreq: TLargeInteger; PerfTime100nSec: TLargeInteger; SystemNameLength: DWORD; SystemNameOffset: DWORD; end; PPerfObjectType = ^TPerfObjectType; TPerfObjectType = record TotalByteLength: DWORD; DefinitionLength: DWORD; HeaderLength: DWORD; ObjectNameTitleIndex: DWORD; ObjectNameTitle: LPWSTR; ObjectHelpTitleIndex: DWORD; ObjectHelpTitle: LPWSTR; DetailLevel: DWORD; NumCounters: DWORD; DefaultCounter: Longint; NumInstances: Longint; CodePage: DWORD; PerfTime: TLargeInteger; PerfFreq: TLargeInteger; end; PPerfCounterDefinition = ^TPerfCounterDefinition; TPerfCounterDefinition = record ByteLength: DWORD; CounterNameTitleIndex: DWORD; CounterNameTitle: LPWSTR; CounterHelpTitleIndex: DWORD; CounterHelpTitle: LPWSTR; DefaultScale: Longint; DetailLevel: DWORD; CounterType: DWORD; CounterSize: DWORD; CounterOffset: DWORD; end; PPerfInstanceDefinition = ^TPerfInstanceDefinition;
TPerfInstanceDefinition = record ByteLength: DWORD; ParentObjectTitleIndex: DWORD; ParentObjectInstance: DWORD; UniqueID: Longint; NameOffset: DWORD; NameLength: DWORD; end; PPerfCounterBlock = ^TPerfCounterBlock; TPerfCounterBlock = record ByteLength: DWORD; end;{Navigation helpers}function FirstObject(PerfData: PPerfDataBlock): PPerfObjectType;begin Result := PPerfObjectType(DWORD(PerfData) + PerfData.HeaderLength);end;function NextObject(PerfObj: PPerfObjectType): PPerfObjectType;begin Result := PPerfObjectType(DWORD(PerfObj) + PerfObj.TotalByteLength);end;function FirstInstance(PerfObj: PPerfObjectType): PPerfInstanceDefinition;begin Result := PPerfInstanceDefinition(DWORD(PerfObj) + PerfObj.DefinitionLength);end;function NextInstance(PerfInst: PPerfInstanceDefinition): PPerfInstanceDefinition;var PerfCntrBlk: PPerfCounterBlock;begin PerfCntrBlk := PPerfCounterBlock(DWORD(PerfInst) + PerfInst.ByteLength); Result := PPerfInstanceDefinition(DWORD(PerfCntrBlk) + PerfCntrBlk.ByteLength);end;function FirstCounter(PerfObj: PPerfObjectType): PPerfCounterDefinition;begin Result := PPerfCounterDefinition(DWORD(PerfObj) + PerfObj.HeaderLength);end;function NextCounter(PerfCntr: PPerfCounterDefinition): PPerfCounterDefinition;begin Result := PPerfCounterDefinition(DWORD(PerfCntr) + PerfCntr.ByteLength);end;{Registry helpers}function GetPerformanceKey(const Machine: string): HKey;var s: string;begin
Result := 0; if Length(Machine) = 0 then Result := HKEY_PERFORMANCE_DATA else begin s := Machine; if Pos('\\', s) <> 1 then s := '\\' + s; if RegConnectRegistry(PChar(s), HKEY_PERFORMANCE_DATA, Result) <> ERROR_SUCCESS then Result := 0; end;end;{TPerfObject}constructor TPerfObject.Create(const AMachine: string; AObjectID: DWORD);begin inherited Create; FList := TList.Create; FMachine := AMachine; FObjectID := AObjectID; ReadInstances;end;destructor TPerfObject.Destroy;var i: Integer;begin for i := 0 to FList.Count - 1 do TPerfInstance(FList[i]).Free; FList.Free; inherited Destroy;end;function TPerfObject.GetCount: Integer;begin Result := FList.Count;end;function TPerfObject.GetInstance(Index: Integer): TPerfInstance;begin Result := FList[Index];end;procedure TPerfObject.ReadInstances;var PerfData: PPerfDataBlock; PerfObj: PPerfObjectType; PerfInst: PPerfInstanceDefinition; PerfCntr, CurCntr: PPerfCounterDefinition;
PtrToCntr: PPerfCounterBlock; BufferSize: Integer; i, j, k: Integer; pData: PLargeInteger; Key: HKey; CurInstance: TPerfInstance;begin for i := 0 to FList.Count - 1 do TPerfInstance(FList[i]).Free; FList.Clear; Key := GetPerformanceKey(FMachine); if Key = 0 then Exit; PerfData := nil; try {Allocate initial buffer for object information} BufferSize := 65536; GetMem(PerfData, BufferSize); {retrieve data} while RegQueryValueEx(Key, PChar(IntToStr(FObjectID)), {Object name} nil, nil, Pointer(PerfData), @BufferSize) = ERROR_MORE_DATA do begin {buffer is too small} Inc(BufferSize, 1024); ReallocMem(PerfData, BufferSize); end; RegCloseKey(HKEY_PERFORMANCE_DATA); {Get the first object type} PerfObj := FirstObject(PerfData); {Process all objects} for i := 0 to PerfData.NumObjectTypes - 1 do begin {Check for requested object} if PerfObj.ObjectNameTitleIndex = FObjectID then begin {Get the first counter} PerfCntr := FirstCounter(PerfObj); if PerfObj.NumInstances > 0 then begin {Get the first instance} PerfInst := FirstInstance(PerfObj); {Retrieve all instances} for k := 0 to PerfObj.NumInstances - 1 do begin {Create entry for instance}
CurInstance := TPerfInstance.Create; CurInstance.FName := WideCharToString(PWideChar(DWORD(PerfInst) + PerfInst.NameOffset)); FList.Add(CurInstance); CurCntr := PerfCntr; {Retrieve all counters} SetLength(CurInstance.FCounters, PerfObj.NumCounters); for j := 0 to PerfObj.NumCounters - 1 do begin PtrToCntr := PPerfCounterBlock(DWORD(PerfInst) + PerfInst.ByteLength); pData := Pointer(DWORD(PtrToCntr) + CurCntr.CounterOffset); {Add counter to array} CurInstance.FCounters[j].Counter := CurCntr.CounterNameTitleIndex; CurInstance.FCounters[j].Value := pData^; {Get the next counter} CurCntr := NextCounter(CurCntr); end; {Get the next instance.} PerfInst := NextInstance(PerfInst); end; end; end; {Get the next object type} PerfObj := NextObject(PerfObj); end; finally {Release buffer} FreeMem(PerfData); {Close remote registry handle} if Key <> HKEY_PERFORMANCE_DATA then RegCloseKey(Key); end;end;procedure GetProcesses(const Machine: string; List: TStrings);var Processes: TPerfObject; i, j: Integer; ProcessID: DWORD;begin Processes := nil; List.Clear; try Processes := TPerfObject.Create(Machine, 230); {230 = Process} for i := 0 to Processes.Count - 1 do {Find process ID}
for j := 0 to Length(Processes[i].Counters) - 1 do if (Processes[i].Counters[j].Counter = 784) then begin ProcessID := Processes[i].Counters[j].Value; if ProcessID <> 0 then List.AddObject(Processes[i].Name, Pointer(ProcessID)); Break; end; finally Processes.Free; end;end;end.
8. Menggunakan Serversocket and Clientsocket// Client Program:// Send 'power' to Client to shutdown the machine.// Send 'reset' to Client to reset the machine.unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, ScktComp;type TForm1 = class(TForm) Clientsocket1: TClientSocket; StatusBar1: TStatusBar; Button1: TButton; Button2: TButton; Edit1: TEdit; Label1: TLabel; Button3: TButton; CheckBox1: TCheckBox; Checkbox2: TCheckBox; procedure Button1Click(Sender : TObject); procedure Button2Click(Sender : TObject); procedure Clientsocket1Error(Sender : TObject; Socket : TCustomWinSocket; ErrorEvent : TErrorEvent; var ErrorCode : integer); procedure Clientsocket1Disconnect(Sender : TObject; Socket : TCustomWinSocket); procedure Clientsocket1Connect(Sender : TObject; Socket : TCustomWinSocket); procedure Button3Click(Sender : TObject); procedure FormClose(Sender : TObject; var Action : TCloseAction); procedure FormDestroy(Sender : TObject); private
{ Private declarations } public { Public declarations } end;var Form1 : TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender : TObject);begin Clientsocket1.Active := True;end;procedure TForm1.Button2Click(Sender : TObject);begin Clientsocket1.Active := False;end;procedure TForm1.Clientsocket1Error(Sender : TObject; Socket : TCustomWinSocket; ErrorEvent : TErrorEvent; var ErrorCode : integer);begin errorcode := 0; StatusBar1.SimpleText := 'Error';end;procedure TForm1.Clientsocket1Disconnect(Sender : TObject; Socket : TCustomWinSocket);begin StatusBar1.SimpleText := 'Disconnect';end;procedure TForm1.Clientsocket1Connect(Sender : TObject; Socket : TCustomWinSocket);begin StatusBar1.SimpleText := Clientsocket1.Address;end;procedure TForm1.Button3Click(Sender : TObject);var ukaz : string; orders : string; Text : string; box : string;begin ukaz := edit1.Text; Clientsocket1.Socket.SendText(ukaz); if checkbox1.Checked = True then begin orders := 'power';
Clientsocket1.Socket.SendText(orders); end; if Checkbox2.Checked = True then begin Text := 'reset'; Clientsocket1.Socket.SendText(Text); end;end;procedure TForm1.FormClose(Sender : TObject; var Action : TCloseAction);begin Clientsocket1.Active := False;end;procedure TForm1.FormDestroy(Sender : TObject);begin Clientsocket1.Active := False;end;end.// Client Programunit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ScktComp, StdCtrls, ShellApi;type TForm1 = class(TForm) Label1: TLabel; Serversocket1: TServerSocket; procedure FormClose(Sender : TObject; var Action : TCloseAction); procedure FormDestroy(Sender : TObject); procedure FormCreate(Sender : TObject); procedure Serversocket1ClientError(Sender : TObject; Socket : TCustomWinSocket; ErrorEvent : TErrorEvent; var ErrorCode : integer); procedure Serversocket1ClientRead(Sender : TObject; Socket : TCustomWinSocket); private { Private declarations } public { Public declarations } end;var Form1 : TForm1;implementation{$R *.dfm}
procedure TForm1.FormClose(Sender : TObject; var Action : TCloseAction);begin Serversocket1.Active := False;end;procedure TForm1.FormDestroy(Sender : TObject);begin Serversocket1.Active := False;end;procedure TForm1.FormCreate(Sender : TObject);begin Serversocket1.Active := True;end;procedure TForm1.Serversocket1ClientError(Sender : TObject; Socket : TCustomWinSocket; ErrorEvent : TErrorEvent; var ErrorCode : integer);begin errorcode := 0;end;procedure TForm1.Serversocket1ClientRead(Sender : TObject; Socket : TCustomWinSocket);var ukaz : string; orders : string; Text : string; box : string;begin ukaz := socket.ReceiveText; label1.Caption := 'reciving...'; ShellExecute(Handle, 'open', PChar(ukaz), PChar(''), nil, sw_show); Text := socket.ReceiveText; orders := socket.ReceiveText; if orders = 'power' then begin ShellExecute(Handle, 'open', PChar('shutdown.exe'), PChar('-s'), nil, sw_show); Application.MessageBox('You will be turned off', 'Warning', mb_iconexclamation); Serversocket1.Active := False; Form1.Close; end; if Text = 'reset' then begin ShellExecute(Handle, 'open', PChar('shutdown.exe'), PChar('-r'), nil, sw_show); Application.MessageBox('You will be reset', 'Warning', mb_iconexclamation); Serversocket1.Active := False; Form1.Close; end;
end;end.
FORM1. Format Currency sesuai Local setting
function GetCurrency(number: PChar): string;var tmpStr: string;begin SetLength(tmpStr, 255); GetCurrencyFormat(LOCALE_SYSTEM_DEFAULT, 0, number, nil, PChar(tmpStr), Length(tmpStr); Result := tmpStr;end;// Beispiel: Example:procedure TForm1.Button1Click(Sender: TObject);begin Application.MessageBox(PChar(GetCurrency(PChar(Edit1.Text))), '', MB_OK);end;
2. Disable Button Close[X] pada FORMprocedure TFMain.FormCreate(Sender: TObject);var hMenuHandle: Integer;begin hMenuHandle := GetSystemMenu(Handle, False); if (hMenuHandle <> 0) then DeleteMenu(hMenuHandle, SC_CLOSE, MF_BYCOMMAND);end;