Latest News

the latest news from our team

Using Data Access – From Delphi 3 with Arrays

The MDMDA session object is being called from a Borland Delphi 3 application.
This sample includes references to an item array (12J1).

The dataset and items are defined as follows:

ITEMS:
ITEM-NO, Z6;
SALES-PERIODS, 12X6;
SALES-HISTORY, 12P12;
MISC, 12J1;
OTHER, J2;

SETS:
NAME: HISTORY, DETAIL (1/18);
ENTRY: ITEM-NO(!HISTORY-M),
SALES-PERIODS,
SALES-HISTORY,
MISC,
OTHER;
CAPACITY: 101;
END.

mdm_001

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids;

type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
MISC: TStringGrid;
Next: TButton;
Rewind: TButton;
Add: TButton;
procedure FormCreate(Sender: TObject);
procedure NextClick(Sender: TObject);
procedure RewindClick(Sender: TObject);
procedure AddClick(Sender: TObject);
private
da : Variant;
db : Variant;
ds : Variant;
t1 : string;
procedure GetItemValues;
procedure SetItemValues;
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

uses
comobj;

procedure TForm1.GetItemValues;
var
t2 : string;
ii : integer;
jj : integer;
begin
t1 := '';
for ii := 0 to 11 do begin
t2 := trim(Misc.Cells[0,ii]);
if ( t2 = '' ) then begin
jj := 0;
end else begin
try
jj := StrToInt ( t2 );
except
jj := 0;
end;
end;
t1 := t1 + format ( '%6d', [jj] );
end;
ds.Item('ITEM-NO') := Edit1.Text;
ds.Item('MISC') := t1;
Edit2.Text := t1;
end;

procedure TForm1.SetItemValues;
var
t2 : string;
ii : integer;
jj : integer;
begin
Edit1.Text := ds.Item('ITEM-NO');
t1 := ds.Item('MISC');
Edit2.Text := t1;
for ii := 0 to 11 do begin
t2 := trim(copy(t1, 1+(ii*6),6));
if ( t2 = '' ) then begin
jj := 0;
end else begin
try
jj := StrToInt ( t2 );
except
jj := 0;
end;
end;
Misc.Cells [0,ii] := IntToStr ( jj );
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
da := CreateOleObject('MdmDA.Session');
da.TraceLevel := 0;
da.HostAddress := 'support';
da.Port := '30002';
da.LoginUser := 'mgr';
da.UserPassword := InputBox('user password','user password', '');
da.LoginGroup := 'util';
da.LoginAccount := 'minisoft';
If Not da.Connect Then begin
ShowMessage ( 'Connect failed' );
exit;
End;
If da.LoginStatus = False Then begin
ShowMessage ( 'Login failed' );
exit;
End;
db := da.AddImageDBRef('MSCARD');
ds := db.AddDatasetRef('HISTORY');
If Not db.Open('MSCARD', 'UTIL', 'MINISOFT', 1, 'DO-ALL') Then begin
ShowMessage ( 'Open failed' );
Exit;
End;
ds.Delimiter := '';
If Not ds.ReadSerialNext('@;') Then begin
ShowMessage ( 'readserialnext failed: ' + ds.ErrorMessage );
Exit;
End;

SetItemValues;

end;

procedure TForm1.NextClick(Sender: TObject);
begin

If Not ds.ReadSerialNext('@;') Then begin
ShowMessage ( 'readserialnext failed: ' + ds.ErrorMessage );
Exit;
End;

SetItemValues;

end;

procedure TForm1.RewindClick(Sender: TObject);
begin

If Not ds.Rewind Then begin
ShowMessage ( 'Rewind Failed: ' + ds.ErrorMessage );
Exit;
End;

end;

procedure TForm1.AddClick(Sender: TObject);
begin

GetItemValues;

If Not ds.Write('@;') Then begin
ShowMessage ( 'Write failed: ' + ds.ErrorMessage );
Exit;
End;

end;

end

Leave a Reply

Your email address will not be published. Required fields are marked *