Skriptovací jazyk - příklady: Porovnání verzí
Z K.A.P.
Skočit na navigaciSkočit na vyhledáváním |
m (Příklad TKAPMemTable) |
||
| Řádek 129: | Řádek 129: | ||
t.Free; // vytvořené objekty je třeba zrušit | t.Free; // vytvořené objekty je třeba zrušit | ||
end; | end; | ||
| + | end. | ||
| + | |||
| + | ---- | ||
| + | |||
| + | var t: TKAPMemTable; | ||
| + | f:TForm; | ||
| + | DBGr: TDBGrid; | ||
| + | ds: TDataSource; | ||
| + | MinA, x: Integer; | ||
| + | begin | ||
| + | t := TKAPMemTable.Create; | ||
| + | try | ||
| + | t.FieldDefs.Add('A',ftInteger,0, false); | ||
| + | t.FieldDefs.Add('B',ftString,30, false); | ||
| + | t.FieldDefs.Add('C',ftfloat,0, false); | ||
| + | t.FieldDefs.Add('D',ftDate,0, false); | ||
| + | t.FieldDefs.Add('E',ftTime,0, false); | ||
| + | t.CreateTable(nil); | ||
| + | // t.IndexFieldNames := 'A;B'; | ||
| + | t.AddIndex('i1', 'A;B',[ixCaseInsensitive]); // nesmi byt prazdna mnozina | ||
| + | t.IndexName := 'i1'; | ||
| + | t.Open; | ||
| + | |||
| + | t.Append; | ||
| + | t.FieldByName('A').AsInteger := 5555; | ||
| + | t.FieldByName('B').AsString := 'TEST'; | ||
| + | t.FieldByName('C').AsFloat := 10.5; | ||
| + | t.Post; | ||
| + | t.Append; | ||
| + | t.FieldByName('A').AsInteger := 4444; | ||
| + | t.FieldByName('D').AsDateTime := Date+1; | ||
| + | t.Post; | ||
| + | t.Append; | ||
| + | t.FieldByName('A').AsInteger := 3333; | ||
| + | t.Post; | ||
| + | t.Append; | ||
| + | t.FieldByName('A').AsInteger := 8888; | ||
| + | t.Post; | ||
| + | |||
| + | t.First; | ||
| + | MinA := t.FieldByName('A').AsInteger; | ||
| + | while not t.EOF do begin | ||
| + | if t.FieldByName('A').AsInteger < MinA then MinA := t.FieldByName('A').AsInteger; | ||
| + | t.Next; | ||
| + | end; | ||
| + | ShowMessage('Min: '+IntToStr(MinA)) | ||
| + | |||
| + | f := TForm.Create(nil); | ||
| + | try | ||
| + | f.Caption := 'Zobrazení MemTable'; | ||
| + | f.Width := 1024; | ||
| + | f.Height := 768; | ||
| + | |||
| + | DBGr:= TDBGrid.Create(f); | ||
| + | DBGr.Parent := f; | ||
| + | DBGr.Align := alClient; | ||
| + | |||
| + | ds:= TDataSource.Create(f); | ||
| + | DBGr.DataSource :=ds; | ||
| + | ds.DataSet := t; | ||
| + | f.ShowModal; | ||
| + | finaly | ||
| + | f.free; | ||
| + | end | ||
| + | // x := t.RecordCount; | ||
| + | finally | ||
| + | t.Free; | ||
| + | end | ||
end. | end. | ||
Verze z 4. 12. 2012, 19:21
Příklad skriptu v syntaxi Pascal:
var i: integer;
s: String;
begin
s:=IniReadString('ScriptTest', 1, True, _AktualniSklad_, '5');
ShowMessage(Settings.Values['INI.FirmaJmeno']+chr(13)+Settings.Values['USER.JmenoUziv']+chr(13)+_KonfigDir_);
LogWrite('Direktivy:'+_Direktivy_);
if s <> '' then
i := StrToInt(s)+1
else
i := -10;
if not IniWriteInteger('ScriptTest', 1, True, _AktualniSklad_, i) then
ShowMessage('V IniWriteInteger se vyskytla chyba');
end.
var s: String; d1, d2: TDateTime; DD, MM, YY : word; begin DecodeDate(Date, YY, MM, DD); if MM=1 then begin // Zjisteni predchoziho mesice MM := 12; YY := YY - 1; end else MM := MM - 1; D1 := EncodeDate(YY, MM, 1); D2 := EncodeDate(YY, MM, DaysInMonth(YY, MM)); S := GSRunReport(6, 1, 'KFG_Datum1='+StrDate(D1)+chr(13)+ 'KFG_Datum='+StrDate(D2)+chr(13)+ 'INI_Jmeno=Pokusný sklad'); //S := GSRunReportV(6, 1, ['KFG_Datum1', 'KFG_Datum', 'INI_Jmeno'],[StrDate(D1), StrDate(D2), 'Pokusný sklad']); ShowMessage(s); end.
var
s: String;
begin
//From, SendTo, FileAttach, Subject, SMTPServer, SMTPSenderName, SMTPPassword, BodyString, ErrMessage
if SendMailBySMTP('odesilatel@posta.cz', 'prijemce@mail.com', 'UZIV\SESTAVA1.SLK'#9'UZIV\SESTAVA2.SES'#13'UZIV\vystup.pdf', 'Test scriptu', 'smtp.posta.cz', 'SMTPjmeno', 'SMTPheslo', 'Testovaci email.'#13'Konec', s) then
ShowMessage('OK '+ s)
else
ShowMessage('CHYBA '+ s);
end.
var MOSCommunicator: TMOSCommunicator;
begin
MOSCommunicator := TMOSCommunicator.Create('MOS.bin', '', '', '', 0);
if MOSCommunicator.SendFile('C:\DIR\DATA1.xml', 'DATA1.XML', '', '', '', True) then
LogWrite('Prenos OK')
else
LogWrite(MOSCommunicator.ErrMessage);
MOSCommunicator.Free;
end.
var MOSCommunicator: TMOSCommunicator;
Info: String;
Velikost: Extended;
Cas: TDateTime;
begin
MOSCommunicator := TMOSCommunicator.Create('', '192.168.17.1', 'MOSuser', 'MOSpswd', 1);
try
if MOSCommunicator.Connect then begin // pokud se připojím, pak se vše realizuje
// v rámci jednoho připojení
// ShowMessage('Pripojeno');
if MOSCommunicator.Connected then begin // test navic
if MOSCommunicator.SendSMS('111222333','Pokus o poslani SMS') then
ShowMessage('SMS odeslana.')
else
ShowMessage('Chyba pri odesilani SMS:'#13+MOSCommunicator.ErrMessage);
if MOSCommunicator.SendFile('C:\DIR\DATA1.xml', 'DATA1.XML', '', '', '', False) then
begin
ShowMessage('Prenos OK');
if MOSCommunicator.GetFileInfo('Sklad6DOC', 'Stavy.xml', Info, Velikost, Cas) then begin
ShowMessage('GetFileInfo:'#13 + Info+ #13 + FloatToStr(Velikost) + #13 + DateTimeToStr(Cas));
if not MOSCommunicator.GetFile('C:\DIR\Stavy2.XML', 'Podslozka\Stavy.xml', 'Sklad6DOC') then
ShowMessage('GetFile:'#13+MOSCommunicator.ErrMessage);
end else
ShowMessage('GetFileInfo:'#13+MOSCommunicator.ErrMessage);
end else
ShowMessage('SendFile'#13+MOSCommunicator.ErrMessage);
MOSCommunicator.Disconnect;
end else
ShowMessage(MOSCommunicator.ErrMessage);
end else
ShowMessage(MOSCommunicator.ErrMessage);
finally
MOSCommunicator.Free;
end;
end.
var
t: TKAPBtrTable;
f: TForm;
DBGrid: TDBGrid;
ds: TDataSource;
begin
ds := nil;
t := TKAPBtrTable.Create;
try // try-finally část není nutná, ale správně se takto řeší problémové situace
t.TableName := 'CISELNIK.btr'; // jméno tabulky bez cesty
t.IndexFieldNames := 'TypCis;Klic1';
t.Open;
f := TForm.Create(Application);
try
f.Caption := 'Zobrazení ' + t.TableName;
f.Position := poDefault;
DBGrid:= TDBGrid.Create(f); // parametr určuje vlastníka prvku DBGrid
DBGrid.Parent := f; // Parent určuje, na kterém formuláři se má DBGrid zobrazit
DBGrid.Align := alClient; // alClient znamená vyplnit celý formulář
ds:= TDataSource.Create(f); // TDataSource propojuje tabulku s vizuálními prvky pro editaci (DBGrid)
DBGrid.DataSource := ds;
ds.DataSet := t;
f.ShowModal; // hlavní okno je třeba vždy otevírat pomocí ShowModal
finally
F.Free; // objekty, kterým byl určen vlastník (DBGrid) se ruší automaticky
end; // při rušení vlastníka (při F.Free se ruší DBGrid i ds)
finally
t.Free; // vytvořené objekty je třeba zrušit
end;
end.
var t: TKAPMemTable;
f:TForm;
DBGr: TDBGrid;
ds: TDataSource;
MinA, x: Integer;
begin
t := TKAPMemTable.Create;
try
t.FieldDefs.Add('A',ftInteger,0, false);
t.FieldDefs.Add('B',ftString,30, false);
t.FieldDefs.Add('C',ftfloat,0, false);
t.FieldDefs.Add('D',ftDate,0, false);
t.FieldDefs.Add('E',ftTime,0, false);
t.CreateTable(nil);
// t.IndexFieldNames := 'A;B';
t.AddIndex('i1', 'A;B',[ixCaseInsensitive]); // nesmi byt prazdna mnozina
t.IndexName := 'i1';
t.Open;
t.Append;
t.FieldByName('A').AsInteger := 5555;
t.FieldByName('B').AsString := 'TEST';
t.FieldByName('C').AsFloat := 10.5;
t.Post;
t.Append;
t.FieldByName('A').AsInteger := 4444;
t.FieldByName('D').AsDateTime := Date+1;
t.Post;
t.Append;
t.FieldByName('A').AsInteger := 3333;
t.Post;
t.Append;
t.FieldByName('A').AsInteger := 8888;
t.Post;
t.First;
MinA := t.FieldByName('A').AsInteger;
while not t.EOF do begin
if t.FieldByName('A').AsInteger < MinA then MinA := t.FieldByName('A').AsInteger;
t.Next;
end;
ShowMessage('Min: '+IntToStr(MinA))
f := TForm.Create(nil);
try
f.Caption := 'Zobrazení MemTable';
f.Width := 1024;
f.Height := 768;
DBGr:= TDBGrid.Create(f);
DBGr.Parent := f;
DBGr.Align := alClient;
ds:= TDataSource.Create(f);
DBGr.DataSource :=ds;
ds.DataSet := t;
f.ShowModal;
finaly
f.free;
end
// x := t.RecordCount;
finally
t.Free;
end
end.