Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TDBEdit - trimming and changing

Status
Not open for further replies.

MatthiasB

IS-IT--Management
Oct 19, 2002
72
DE
Hi everyone,

getting more understanding of Delphi (5) and InterBase (OE), but still searching the paths - this will be a bit longer one :)

I have a main form with DBGrid showing (potentially subset) of an InterBase view (4 tables master/detail chain, well normalized); access is done via IBX. On double-click or select+button in the grid I store the main table key of the selected in public variable Person_ID of another form:

Code:
  //--  make primary key available
  FORM_EditorPerson.Person_ID := IBQuery.Fields.FieldByName('PERSON_ID').AsInteger;
  //--  call detail editor
  if FORM_EditorPerson.ShowModal = mrOK then begin
..

That form is a detail editor for people. On FormCreate I create the connection to Interbase:

Code:
//--  activate DB
IBDatabase := TIBDatabase.Create (nil);
with IBDatabase do begin
  DatabaseName := AboDatabasePath;  //--  from registry
  SQLDialect := 3;   //--  IB SQL-3
  LoginPrompt := false;  //--  auto-login
  Params.Add ('user_name=...');
  Params.Add ('password=...');
  Connected := true;                 
end;
IBDataSet := TIBDataSet.Create (nil);
with IBDataSet do begin
  Database := IBDatabase;
  CachedUpdates := true;  //--  wanna write
end;
IBTransaction := TIBTransaction.Create (nil);
with IBTransaction do begin
  DefaultDatabase := IBDatabase;
  Active := true;
end;
IBQuery := TIBQuery.Create (nil);
with IBQuery do begin
  Database := IBDatabase;
  Transaction := IBTransaction;
end;
DataSource := TDataSource.Create (nil);
DataSource.DataSet := IBQuery;
  
//--  connect VCL components to DB
DBEdit_Lastname.DataSource := DataSource;
..

The field name of the DBEdits I set at design time, on FormShow of the detail editor I retrieve the record and the fields get nicely populated:

Code:
IBQuery.SQL.Text := 'select * from V_PERSON_ADDR '
        + 'where PERSON_ID = ' + inttostr(PERSON_ID);
IBQuery.Active := true;

First problem now: the fields have trailing spaces due to length on the database - can that be trimmed easily?

More important: I cannot edit any of the fields, they all reject any typing - someone knows what that is caused by? This one is really confusing me.

And a final one, just to check if I got the Delphi documentation right and do not try something that'll never work: the IBUpdateSQL component I have to create for each of the tables in the database view, so I can write back? Or is it also possible some way to use IBSQL and create adhoc update statements? With this mini application performance isn't an issue, just around 3000 people on the master table.

Thanks!
Matthias
 
Hi again,

one other thing I came across that might give a hint: OnClick of a button I add, depending on the ReadOnly flag of one of the fields, something to a TDBMemo; when executing it show 'r/w':

Code:
if DBEdit_Lastname.ReadOnly
  then DBMemo_Comment.Lines.Add ('Lastname r/o')
  else DBMemo_Comment.Lines.Add ('Lastname r/w');

Funny enough now, when I place the cursor in that memo, either click or tab, the memo lines fall back to what they are on the DB.

Thanks,
Matthias

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top