jpdupont
asked on
How to connect non db-aware components to a table ?
Hello,
I would like to connect a non db aware memo (TColorMemo) to a MemoField in a table.
I connect other fields to standard TDBMemo or TDBEdit.
Where put the code to
- fill the ColorMemo text with the field value,
- fill the field with the ColorMemo text ?
I would like to synchronize the ColorMemo with the other DBAware controls on the form, and go to edit mode when the user modify the ColorMemo text.
Thanks for the help,
Jean-Pol
I would like to connect a non db aware memo (TColorMemo) to a MemoField in a table.
I connect other fields to standard TDBMemo or TDBEdit.
Where put the code to
- fill the ColorMemo text with the field value,
- fill the field with the ColorMemo text ?
I would like to synchronize the ColorMemo with the other DBAware controls on the form, and go to edit mode when the user modify the ColorMemo text.
Thanks for the help,
Jean-Pol
ASKER
Hi Meikl,
Thanks for the answer. I know this ...
I want a really complete solution : I want the colormemo act as a DBAWARE control ...
Ex : When I put some char in the colormemo, the DBNavigator remains in browse mode. If I put some code in the ColorMemo.Onchange event, I'm able to set the table to edit mode. But when I click on the arrow to scroll to the next record, the content of the memo is not set to the MemoField (In the BeforeScroll, the table state is on "browse" ...).
Table and DataSource have many events ... where put my code ???
If you give me a complete solution, with sample code I will increase the points ...
Thanks,
Jean-Pol
Thanks for the answer. I know this ...
I want a really complete solution : I want the colormemo act as a DBAWARE control ...
Ex : When I put some char in the colormemo, the DBNavigator remains in browse mode. If I put some code in the ColorMemo.Onchange event, I'm able to set the table to edit mode. But when I click on the arrow to scroll to the next record, the content of the memo is not set to the MemoField (In the BeforeScroll, the table state is on "browse" ...).
Table and DataSource have many events ... where put my code ???
If you give me a complete solution, with sample code I will increase the points ...
Thanks,
Jean-Pol
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hi jean-pol,
the first try
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Mask, DBCtrls, Db, DBTables, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
DataSource1: TDataSource;
Table1: TTable;
DBEdit1: TDBEdit;
DBNavigator1: TDBNavigator;
procedure Memo1Change(Sender: TObject);
procedure Table1AfterScroll(DataSet: TDataSet);
procedure Table1BeforePost(DataSet: TDataSet);
procedure Table1AfterCancel(DataSet: TDataSet);
procedure Table1NewRecord(DataSet: TDataSet);
private
fScrollEvent : Boolean;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
//if there any change of the memocontent
//memo OnChange event
procedure TForm1.Memo1Change(Sender: TObject);
begin
if not FScrollEvent then //avoid editmode afterscroll
If (Table1.State = dsEdit) or
(Table1.State = dsInsert) then
//all ok
else
Table1.Edit
else
FScrollEvent := False;
end;
//Table AfterScroll Event
procedure TForm1.Table1AfterScroll(D ataSet: TDataSet);
begin
FScrollEvent := True; //we've a scroll event
memo1.Text := TBlobField(Table1.FieldByN ame('Text' )).AsStrin g;
end;
//place the memo content into the BlobField
//Table BeforePost Event
procedure TForm1.Table1BeforePost(Da taSet: TDataSet);
begin
TBlobField(Table1.FieldByN ame('Text' )).AsStrin g := memo1.Text;
end;
//edit is canceled, restore memo-content
//Table AfterCancel Event
procedure TForm1.Table1AfterCancel(D ataSet: TDataSet);
begin
memo1.Text := TBlobField(Table1.FieldByN ame('Text' )).AsStrin g;
end;
//clear the memo on newrecord
//Table OnNewRecord Event
procedure TForm1.Table1NewRecord(Dat aSet: TDataSet);
begin
memo1.lines.Clear;
end;
end.
let me know, if this match your needs
meikl
the first try
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Mask, DBCtrls, Db, DBTables, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
DataSource1: TDataSource;
Table1: TTable;
DBEdit1: TDBEdit;
DBNavigator1: TDBNavigator;
procedure Memo1Change(Sender: TObject);
procedure Table1AfterScroll(DataSet:
procedure Table1BeforePost(DataSet: TDataSet);
procedure Table1AfterCancel(DataSet:
procedure Table1NewRecord(DataSet: TDataSet);
private
fScrollEvent : Boolean;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
//if there any change of the memocontent
//memo OnChange event
procedure TForm1.Memo1Change(Sender:
begin
if not FScrollEvent then //avoid editmode afterscroll
If (Table1.State = dsEdit) or
(Table1.State = dsInsert) then
//all ok
else
Table1.Edit
else
FScrollEvent := False;
end;
//Table AfterScroll Event
procedure TForm1.Table1AfterScroll(D
begin
FScrollEvent := True; //we've a scroll event
memo1.Text := TBlobField(Table1.FieldByN
end;
//place the memo content into the BlobField
//Table BeforePost Event
procedure TForm1.Table1BeforePost(Da
begin
TBlobField(Table1.FieldByN
end;
//edit is canceled, restore memo-content
//Table AfterCancel Event
procedure TForm1.Table1AfterCancel(D
begin
memo1.Text := TBlobField(Table1.FieldByN
end;
//clear the memo on newrecord
//Table OnNewRecord Event
procedure TForm1.Table1NewRecord(Dat
begin
memo1.lines.Clear;
end;
end.
let me know, if this match your needs
meikl
ASKER
Hi Meikl,
I try your code. One problem :
I scroll the table. OK
I put a few char in the ColorMemo, the table go to EDIT mode : OK
I scroll the table : the ColorMemo text is not posted to the field. (The problem !)
But if I put some char in the ColorMemo AND in a dbedit control, when I scroll the table, the ColorMemo text is correctly posted to the memoField.
I try to force a post in "before scroll" if the table is in edit or insert state : no effect.
Thanks for the help,
Jean-Pol
I try your code. One problem :
I scroll the table. OK
I put a few char in the ColorMemo, the table go to EDIT mode : OK
I scroll the table : the ColorMemo text is not posted to the field. (The problem !)
But if I put some char in the ColorMemo AND in a dbedit control, when I scroll the table, the ColorMemo text is correctly posted to the memoField.
I try to force a post in "before scroll" if the table is in edit or insert state : no effect.
Thanks for the help,
Jean-Pol
hi jean-pol,
how do you scroll the table,
because i didn't have this problem.
i enter some text in the tmemo of my sample
the tabel becomes the edit-state and
use the navigator to scroll to next record,
the post event appears then automatically
and saves the changes,
the afterscroll-event loads
the new content.
meikl
how do you scroll the table,
because i didn't have this problem.
i enter some text in the tmemo of my sample
the tabel becomes the edit-state and
use the navigator to scroll to next record,
the post event appears then automatically
and saves the changes,
the afterscroll-event loads
the new content.
meikl
ASKER
Meikl,
I use the DBNavigator to scroll ...
I work with a DBISAMTable.
D5.01 PRO, french, Win98SE.
The post event appears only if I modify a DBAware component (like DBEdit).
If I click on the "Post" button, all is saved ...
JP
I use the DBNavigator to scroll ...
I work with a DBISAMTable.
D5.01 PRO, french, Win98SE.
The post event appears only if I modify a DBAware component (like DBEdit).
If I click on the "Post" button, all is saved ...
JP
ASKER
Any other idea ?
for get
you can use the afterscroll event of
your ttable or tquery and use a code like this
MyColorMemoControl.Text := TBlobField(MyTable.FieldBy
for set
you can use the beforepost event of
your ttable or tquery and use a code like this
TBlobField(MyTable.FieldBy
meikl