 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Werner Guest
|
Posted: Tue Apr 17, 2007 8:13 am Post subject: IWDBGrid - IWEdit -IWCheckBox - post |
|
|
I'm trying to use
1. edit field in IWDBGrid
2. using a checkbox in IWDBGrid.
So far I could post a checkBox with the code bollow.
It works perfect, but when doing a lot of action, the posts are getting
SLOWER and SLOWER.
It seems that with every click, the onRendering start over, and thus
creating more CheckBoxes ??
1. Do I need to free and nil the checkbox at some place ?
2. Is the code below safe to use? and what is best to use TIWDBCheckBox or
IWCheckBox
3. How to use this technique to edit a field, because the edit has no
onclick event?
Any idee is welcom
procedure TIWForm1.UpdateFieldClick(ASender: TObject);
begin
//UserSession.Table1.RecNo:=(ASender as TIWCheckBox).Tag;
UserSession.Table1.RecNo:=(ASender as TIWDBCheckBox).Tag;
if UserSession.table1.state <> dsEdit then UserSession.Table1.Edit;
UserSession.Table1.FieldByName('Updated').AsBoolean:=not
UserSession.Table1.FieldByName('Updated').AsBoolean;
UserSession.Table1.post;
end;
procedure TIWForm1.IWDBGrid1RenderCell(ACell: TIWGridCell; const ARow,
AColumn: Integer);
var dbCB:TIWDBCheckBox;
//cb :TIWCheckBox;
begin
(* using the TIWDBCheckBox *)
if (AColumn = 4) and (ARow>0) then begin
dbCB := TIWDBCheckBox.Create(Self); //
must this be freeed somewhere??
dbCB.DataField ='Updated';
dbCB.DataSource:=UserSession.DataSource1;
dbCB.Tag :=UserSession.Table1.RecNo;
dbCB.OnClick :=UpdateFieldClick;
dbCB.Caption :='';
ACell.Text :='';
ACell.Control := dbCB;
end;
(* using the TIWCheckBox
if (AColumn = 4) and (ARow>0) then begin
CB:= TIWCheckBox.Create(self);
CB.checked :=UserSession.Table1.FieldByName('Updated').AsBoolean;
CB.Tag :=UserSession.Table1.RecNo;
CB.OnClick :=UpdateFieldClick;
CB.Caption :='';
ACell.text :='';
ACell.Control :=CB;
end;
*)
end; |
|
| Back to top |
|
 |
Farshad Guest
|
Posted: Tue Apr 17, 2007 2:53 pm Post subject: Re: IWDBGrid - IWEdit -IWCheckBox - post |
|
|
You shouldn't create objects in OnRender event. It fills your form with lots
of CheckBoxes after a few run. Not to mention the resource leak that occurs
each time you create a new CheckBox without freeing previous ones. You must
create a static set of checkboxes in OnCreate event and free them in
OnDestroy event. If you want to create them in OnRender event dynimacally
then you must keep track of what you've created and free them when OnDestroy
is triggered. However you must be aware NOT to create same object in same
cell twice or more.
Delphi do not do garbage collection. The general rule is that you must Free
everything you Create programatically.
"Werner" <nospam@nowhere> wrote in message
news:46246ceb$1 (AT) newsgroups (DOT) borland.com...
| Quote: | I'm trying to use
1. edit field in IWDBGrid
2. using a checkbox in IWDBGrid.
So far I could post a checkBox with the code bollow.
It works perfect, but when doing a lot of action, the posts are getting
SLOWER and SLOWER.
It seems that with every click, the onRendering start over, and thus
creating more CheckBoxes ??
1. Do I need to free and nil the checkbox at some place ?
2. Is the code below safe to use? and what is best to use TIWDBCheckBox or
IWCheckBox
3. How to use this technique to edit a field, because the edit has no
onclick event?
Any idee is welcom
procedure TIWForm1.UpdateFieldClick(ASender: TObject);
begin
//UserSession.Table1.RecNo:=(ASender as TIWCheckBox).Tag;
UserSession.Table1.RecNo:=(ASender as TIWDBCheckBox).Tag;
if UserSession.table1.state <> dsEdit then UserSession.Table1.Edit;
UserSession.Table1.FieldByName('Updated').AsBoolean:=not
UserSession.Table1.FieldByName('Updated').AsBoolean;
UserSession.Table1.post;
end;
procedure TIWForm1.IWDBGrid1RenderCell(ACell: TIWGridCell; const ARow,
AColumn: Integer);
var dbCB:TIWDBCheckBox;
//cb :TIWCheckBox;
begin
(* using the TIWDBCheckBox *)
if (AColumn = 4) and (ARow>0) then begin
dbCB := TIWDBCheckBox.Create(Self); //
must this be freeed somewhere??
dbCB.DataField ='Updated';
dbCB.DataSource:=UserSession.DataSource1;
dbCB.Tag :=UserSession.Table1.RecNo;
dbCB.OnClick :=UpdateFieldClick;
dbCB.Caption :='';
ACell.Text :='';
ACell.Control := dbCB;
end;
(* using the TIWCheckBox
if (AColumn = 4) and (ARow>0) then begin
CB:= TIWCheckBox.Create(self);
CB.checked :=UserSession.Table1.FieldByName('Updated').AsBoolean;
CB.Tag :=UserSession.Table1.RecNo;
CB.OnClick :=UpdateFieldClick;
CB.Caption :='';
ACell.text :='';
ACell.Control :=CB;
end;
*)
end;
|
|
|
| Back to top |
|
 |
Werner Guest
|
Posted: Mon Apr 23, 2007 8:12 am Post subject: Re: IWDBGrid - IWEdit -IWCheckBox - post |
|
|
Do I need to create as many checkboxes versus records in the OnCreate?,
wouldn't that be an overhead, or is there an other way.
Don't know where to start, could you give me an example please?
"Farshad" <farshad (AT) fmsoft (DOT) net> schreef in bericht
news:46249938 (AT) newsgroups (DOT) borland.com...
| Quote: | You shouldn't create objects in OnRender event. It fills your form with
lots of CheckBoxes after a few run. Not to mention the resource leak that
occurs each time you create a new CheckBox without freeing previous ones.
You must create a static set of checkboxes in OnCreate event and free them
in OnDestroy event. If you want to create them in OnRender event
dynimacally then you must keep track of what you've created and free them
when OnDestroy is triggered. However you must be aware NOT to create same
object in same cell twice or more.
Delphi do not do garbage collection. The general rule is that you must
Free everything you Create programatically.
"Werner" <nospam@nowhere> wrote in message
news:46246ceb$1 (AT) newsgroups (DOT) borland.com...
I'm trying to use
1. edit field in IWDBGrid
2. using a checkbox in IWDBGrid.
So far I could post a checkBox with the code bollow.
It works perfect, but when doing a lot of action, the posts are getting
SLOWER and SLOWER.
It seems that with every click, the onRendering start over, and thus
creating more CheckBoxes ??
1. Do I need to free and nil the checkbox at some place ?
2. Is the code below safe to use? and what is best to use TIWDBCheckBox
or
IWCheckBox
3. How to use this technique to edit a field, because the edit has no
onclick event?
Any idee is welcom
procedure TIWForm1.UpdateFieldClick(ASender: TObject);
begin
//UserSession.Table1.RecNo:=(ASender as TIWCheckBox).Tag;
UserSession.Table1.RecNo:=(ASender as TIWDBCheckBox).Tag;
if UserSession.table1.state <> dsEdit then UserSession.Table1.Edit;
UserSession.Table1.FieldByName('Updated').AsBoolean:=not
UserSession.Table1.FieldByName('Updated').AsBoolean;
UserSession.Table1.post;
end;
procedure TIWForm1.IWDBGrid1RenderCell(ACell: TIWGridCell; const ARow,
AColumn: Integer);
var dbCB:TIWDBCheckBox;
//cb :TIWCheckBox;
begin
(* using the TIWDBCheckBox *)
if (AColumn = 4) and (ARow>0) then begin
dbCB := TIWDBCheckBox.Create(Self); //
must this be freeed somewhere??
dbCB.DataField ='Updated';
dbCB.DataSource:=UserSession.DataSource1;
dbCB.Tag :=UserSession.Table1.RecNo;
dbCB.OnClick :=UpdateFieldClick;
dbCB.Caption :='';
ACell.Text :='';
ACell.Control := dbCB;
end;
(* using the TIWCheckBox
if (AColumn = 4) and (ARow>0) then begin
CB:= TIWCheckBox.Create(self);
CB.checked :=UserSession.Table1.FieldByName('Updated').AsBoolean;
CB.Tag :=UserSession.Table1.RecNo;
CB.OnClick :=UpdateFieldClick;
CB.Caption :='';
ACell.text :='';
ACell.Control :=CB;
end;
*)
end;
|
|
|
| Back to top |
|
 |
Ricardo Guest
|
Posted: Mon Apr 23, 2007 3:09 pm Post subject: Re: IWDBGrid - IWEdit -IWCheckBox - post |
|
|
Hello Werner,
There is also an other way. I do not create components at runtime. Instead i
use the onmRenderCell of the IWGrid. For the cell which need a
RadioButton/Checkbox i set the ACell.RawText := True; Then i put in the
ACell.Text some html, like;
IF (AColumn = 0) Then Begin
ACell.RawText := True;
ACell.Text := '<input type=radio name="sel" value="%d" onclick="return
SubmitClickConfirm(''btnRadioHandler'', ''%d'', true, '''');">';
End;
Instead of using the SubmitClickConfirm you can also use with some
javascript and put the selected values into hiddenfields. I hope this give
you some direction.
Ricardo
"Werner" <nospam@nowhere> wrote in message
news:462c6381$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Do I need to create as many checkboxes versus records in the OnCreate?,
wouldn't that be an overhead, or is there an other way.
Don't know where to start, could you give me an example please?
"Farshad" <farshad (AT) fmsoft (DOT) net> schreef in bericht
news:46249938 (AT) newsgroups (DOT) borland.com...
You shouldn't create objects in OnRender event. It fills your form with
lots of CheckBoxes after a few run. Not to mention the resource leak
that
occurs each time you create a new CheckBox without freeing previous
ones.
You must create a static set of checkboxes in OnCreate event and free
them
in OnDestroy event. If you want to create them in OnRender event
dynimacally then you must keep track of what you've created and free
them
when OnDestroy is triggered. However you must be aware NOT to create
same
object in same cell twice or more.
Delphi do not do garbage collection. The general rule is that you must
Free everything you Create programatically.
"Werner" <nospam@nowhere> wrote in message
news:46246ceb$1 (AT) newsgroups (DOT) borland.com...
I'm trying to use
1. edit field in IWDBGrid
2. using a checkbox in IWDBGrid.
So far I could post a checkBox with the code bollow.
It works perfect, but when doing a lot of action, the posts are getting
SLOWER and SLOWER.
It seems that with every click, the onRendering start over, and thus
creating more CheckBoxes ??
1. Do I need to free and nil the checkbox at some place ?
2. Is the code below safe to use? and what is best to use TIWDBCheckBox
or
IWCheckBox
3. How to use this technique to edit a field, because the edit has no
onclick event?
Any idee is welcom
procedure TIWForm1.UpdateFieldClick(ASender: TObject);
begin
//UserSession.Table1.RecNo:=(ASender as TIWCheckBox).Tag;
UserSession.Table1.RecNo:=(ASender as TIWDBCheckBox).Tag;
if UserSession.table1.state <> dsEdit then UserSession.Table1.Edit;
UserSession.Table1.FieldByName('Updated').AsBoolean:=not
UserSession.Table1.FieldByName('Updated').AsBoolean;
UserSession.Table1.post;
end;
procedure TIWForm1.IWDBGrid1RenderCell(ACell: TIWGridCell; const ARow,
AColumn: Integer);
var dbCB:TIWDBCheckBox;
//cb :TIWCheckBox;
begin
(* using the TIWDBCheckBox *)
if (AColumn = 4) and (ARow>0) then begin
dbCB := TIWDBCheckBox.Create(Self); //
must this be freeed somewhere??
dbCB.DataField ='Updated';
dbCB.DataSource:=UserSession.DataSource1;
dbCB.Tag :=UserSession.Table1.RecNo;
dbCB.OnClick :=UpdateFieldClick;
dbCB.Caption :='';
ACell.Text :='';
ACell.Control := dbCB;
end;
(* using the TIWCheckBox
if (AColumn = 4) and (ARow>0) then begin
CB:= TIWCheckBox.Create(self);
CB.checked :=UserSession.Table1.FieldByName('Updated').AsBoolean;
CB.Tag :=UserSession.Table1.RecNo;
CB.OnClick :=UpdateFieldClick;
CB.Caption :='';
ACell.text :='';
ACell.Control :=CB;
end;
*)
end;
|
|
|
| Back to top |
|
 |
Werner Guest
|
Posted: Mon Apr 23, 2007 3:55 pm Post subject: Re: IWDBGrid - IWEdit -IWCheckBox - post |
|
|
Ok, I tried this code bellow, and it works much faster now,
BUT when freeing the checkboxes I got an error at component 31, but there
are 59 components ?? Cannot figure out what's wrong
Still wondering when having lot of records, creating a checkbox for everone
is the right approch?
Any comments or get a shorter/better way I would appriciate it
procedure TIWForm1.IWAppFormCreate(Sender: TObject);
var CB:TIWCheckBox;
begin
UserSession.Table1.First;
while not UserSession.Table1.eof do begin
CB := TIWCheckBox.Create(self);
CB.Name :='CB'+IntToStr(UserSession.Table1.RecNo);
CB.Tag :=UserSession.Table1.RecNo;
CB.OnClick :=UpdateFieldClick;
CB.Caption :='';
UserSession.Table1.next;
end;
end;
procedure TIWForm1.IWAppFormDestroy(Sender: TObject);
var i:integer;
begin
for i := 0 to ComponentCount -1 do
if Components[i] is TIWCheckBox then TIWCheckBox(Components[i]).Free;
// got a error ListIndex out of bounds (31) at the 31st Component ??
// ComponentsCounts = 59, Total checkBoxes = 55
end;
procedure TIWForm1.UpdateFieldClick(ASender: TObject);
begin
UserSession.Table1.RecNo:=(ASender as TIWCheckBox).Tag;
if UserSession.table1.state <> dsEdit then UserSession.Table1.Edit;
UserSession.Table1.FieldByName('Updated').AsBoolean:=not
UserSession.Table1.FieldByName('Updated').AsBoolean;
UserSession.Table1.post;
end;
procedure TIWForm1.IWDBGrid1RenderCell(ACell: TIWGridCell; const ARow,
AColumn: Integer);
var CB:TIWCheckBox;
begin
if (AColumn = 4) and (ARow>0) then begin
CB:=
TIWCheckBox(FindComponent('CB'+IntToStr(UserSession.Table1.RecNo)));
if CB<>nil then begin
CB.checked :=UserSession.Table1.FieldByName('Updated').AsBoolean;
ACell.Control:=CB;
ACell.text :='';
end;
end;
end;
"Farshad" <farshad (AT) fmsoft (DOT) net> schreef in bericht
news:46249938 (AT) newsgroups (DOT) borland.com...
| Quote: | You shouldn't create objects in OnRender event. It fills your form with
lots of CheckBoxes after a few run. Not to mention the resource leak that
occurs each time you create a new CheckBox without freeing previous ones.
You must create a static set of checkboxes in OnCreate event and free them
in OnDestroy event. If you want to create them in OnRender event
dynimacally then you must keep track of what you've created and free them
when OnDestroy is triggered. However you must be aware NOT to create same
object in same cell twice or more.
Delphi do not do garbage collection. The general rule is that you must
Free everything you Create programatically.
|
|
|
| Back to top |
|
 |
Werner Guest
|
Posted: Mon Apr 23, 2007 4:18 pm Post subject: Re: IWDBGrid - IWEdit -IWCheckBox - post |
|
|
Dear Ricardo,
It looks a great approch, but cannot get it done. I'm very new about the
javascript and html.
I get the checkbox in the grid, but nothing works so far.
Don't know how to assign the %d var and get the value in the table.
Could you give more info how to do this?
Werner
procedure TIWForm1.IWDBGrid1RenderCell(ACell: TIWGridCell; const ARow,
AColumn: Integer);
var CB:TIWCheckBox;
begin
if (AColumn = 4) and (ARow>0) then begin
ACell.RawText:=True;
ACell.Text :=
'<input type=checkbox name="sel" value="%d" onclick="return
SubmitClickConfirm(''checkboxHandler'', ''%d'', true, '''');">';
end;
end;
"Ricardo" <r.bas (AT) qsa (DOT) nl> schreef in bericht
news:462c86ad$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Hello Werner,
There is also an other way. I do not create components at runtime. Instead
i
use the onmRenderCell of the IWGrid. For the cell which need a
RadioButton/Checkbox i set the ACell.RawText := True; Then i put in the
ACell.Text some html, like;
IF (AColumn = 0) Then Begin
ACell.RawText := True;
ACell.Text := '<input type=radio name="sel" value="%d"
onclick="return
SubmitClickConfirm(''btnRadioHandler'', ''%d'', true, '''');">';
End;
Instead of using the SubmitClickConfirm you can also use with some
javascript and put the selected values into hiddenfields. I hope this give
you some direction.
Ricardo
"Werner" <nospam@nowhere> wrote in message
news:462c6381$1 (AT) newsgroups (DOT) borland.com...
Do I need to create as many checkboxes versus records in the OnCreate?,
wouldn't that be an overhead, or is there an other way.
Don't know where to start, could you give me an example please?
"Farshad" <farshad (AT) fmsoft (DOT) net> schreef in bericht
news:46249938 (AT) newsgroups (DOT) borland.com...
You shouldn't create objects in OnRender event. It fills your form with
lots of CheckBoxes after a few run. Not to mention the resource leak
that
occurs each time you create a new CheckBox without freeing previous
ones.
You must create a static set of checkboxes in OnCreate event and free
them
in OnDestroy event. If you want to create them in OnRender event
dynimacally then you must keep track of what you've created and free
them
when OnDestroy is triggered. However you must be aware NOT to create
same
object in same cell twice or more.
Delphi do not do garbage collection. The general rule is that you must
Free everything you Create programatically.
"Werner" <nospam@nowhere> wrote in message
news:46246ceb$1 (AT) newsgroups (DOT) borland.com...
I'm trying to use
1. edit field in IWDBGrid
2. using a checkbox in IWDBGrid.
So far I could post a checkBox with the code bollow.
It works perfect, but when doing a lot of action, the posts are
getting
SLOWER and SLOWER.
It seems that with every click, the onRendering start over, and thus
creating more CheckBoxes ??
1. Do I need to free and nil the checkbox at some place ?
2. Is the code below safe to use? and what is best to use
TIWDBCheckBox
or
IWCheckBox
3. How to use this technique to edit a field, because the edit has no
onclick event?
Any idee is welcom
procedure TIWForm1.UpdateFieldClick(ASender: TObject);
begin
//UserSession.Table1.RecNo:=(ASender as TIWCheckBox).Tag;
UserSession.Table1.RecNo:=(ASender as TIWDBCheckBox).Tag;
if UserSession.table1.state <> dsEdit then UserSession.Table1.Edit;
UserSession.Table1.FieldByName('Updated').AsBoolean:=not
UserSession.Table1.FieldByName('Updated').AsBoolean;
UserSession.Table1.post;
end;
procedure TIWForm1.IWDBGrid1RenderCell(ACell: TIWGridCell; const ARow,
AColumn: Integer);
var dbCB:TIWDBCheckBox;
//cb :TIWCheckBox;
begin
(* using the TIWDBCheckBox *)
if (AColumn = 4) and (ARow>0) then begin
dbCB := TIWDBCheckBox.Create(Self);
//
must this be freeed somewhere??
dbCB.DataField ='Updated';
dbCB.DataSource:=UserSession.DataSource1;
dbCB.Tag :=UserSession.Table1.RecNo;
dbCB.OnClick :=UpdateFieldClick;
dbCB.Caption :='';
ACell.Text :='';
ACell.Control := dbCB;
end;
(* using the TIWCheckBox
if (AColumn = 4) and (ARow>0) then begin
CB:= TIWCheckBox.Create(self);
CB.checked :=UserSession.Table1.FieldByName('Updated').AsBoolean;
CB.Tag :=UserSession.Table1.RecNo;
CB.OnClick :=UpdateFieldClick;
CB.Caption :='';
ACell.text :='';
ACell.Control :=CB;
end;
*)
end;
|
|
|
| Back to top |
|
 |
Loren Szendre Guest
|
Posted: Tue Apr 24, 2007 1:45 am Post subject: Re: IWDBGrid - IWEdit -IWCheckBox - post |
|
|
Werner,
It looks like your loop through ComponentCount changes the
ComponentCount whilst it executes. I think you can get away with that
kind of code if you start from the end and work toward the beginning:
for i := ComponentCount-1 downto 0 do
// your thing
or you might need to store the ComponentCount in a variable to use in
your for loop.
Loren |
|
| Back to top |
|
 |
Werner Guest
|
Posted: Tue Apr 24, 2007 8:13 am Post subject: Re: IWDBGrid - IWEdit -IWCheckBox - post |
|
|
Thank you Loren, you're absolutely right. So logical... Freeing works
perfect now.
Werner
procedure TIWForm1.IWAppFormDestroy(Sender: TObject);
var i:integer;
begin
{ free checkboxes from end to begin! }
for i := ComponentCount-1 downto 0 do
if Components[i] is TIWCheckBox then TIWCheckBox(Components[i]).Free;
end;
"Loren Szendre" <zorenlendry (AT) yahoo (DOT) com> schreef in bericht
news:462d126f$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Werner,
It looks like your loop through ComponentCount changes the ComponentCount
whilst it executes. I think you can get away with that kind of code if you
start from the end and work toward the beginning:
for i := ComponentCount-1 downto 0 do
// your thing
or you might need to store the ComponentCount in a variable to use in your
for loop.
Loren |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|