request for advices [Edit] |
|
I'll be thankful for any advices about the following codes which I used as OnBeforeDelete, OnBeforeEdit & OnBeforeInsert events for some TClientDataSet in my data module. Actually the codes compiled successfully, but I wonder if there is any drawback or memory leakage.beyond the codes.
Thank you very much.
Regards,
Tjioe Hian Pin
---------------------------------------------------------------------------------
// TCDM is a TDataModule
// OV_Amount is a LargeInt global variable
// function Master( DS: TDataSet ): TClientDataSet; -> a function returning TClientDataSet which is master of the DS
procedure TCDM.NDKD_B_Del(DataSet: TDataSet);
var CDSMaster: TClientDataSet;
begin
OV_Amount:= DataSet.FindField('Amount').AsLargeInt;
CDSMaster:= Master(DataSet);
if CDSMaster.FindField('Gen').ReadOnly or (CDSMaster.FindField('Amount').AsLargeInt-OV_Amount < 0) then
Abort;
end;
procedure TCDM.NDKD_B_Edit(DataSet: TDataSet);
var CDSMaster: TClientDataSet;
begin
CDSMaster:= Master(DataSet);
if CDSMaster.FindField('Gen').ReadOnly then
Abort;
OV_Amount:= DataSet.FindField('Amount').AsLargeInt;
end;
procedure TCDM.NDKD_B_Ins(DataSet: TDataSet);
var CDSMaster: TClientDataSet;
begin
CDSMaster:= Master(DataSet);
if CDSMaster.FindField('Gen').ReadOnly or (CDSMaster.FindField('Amount').AsLargeInt > 999999999).then
Abort;
OV_Amount:= 0;
end;
------------------------------------------------------------------------------
|
> {quote:title=Tjioe Hian Pin wrote:}{quote}
> I'll be thankful for any advices about the following codes which I used as OnBeforeDelete, OnBeforeEdit & OnBeforeInsert events for some TClientDataSet in my data module. Actually the codes compiled successfully, but I wonder if there is any drawback or memory leakage.beyond the codes.
>
> // function Master( DS: TDataSet ): TClientDataSet; -> a function returning TClientDataSet which is master of the DS
Can we see the source of Master( DS ....
Is it creating a new CDS if so you'll be bleeding the instances of it
eg
{code}
function Master( DS: TDataSet ): TClientDataSet;
....
result := TClientDataSet.create...
end;
{code}
if so in your functions you need
{code}
procedure TCDM.....
var
CDSMaster: TClientDataSet;
begin
CDSMaster:= Master(DataSet);
try
if ...
Abort;
.....
finally
CDSMaster.free;
end;
end;
{code}
Otherwise all seems good ... but the full version of FastMM is your friend in this situation
--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"
|