Mega Search
23.2 Million


Sign Up

Make a donation  
request for advices [Edit]  
News Group: embarcadero.public.delphi.database.dbexpress

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;

------------------------------------------------------------------------------

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 25-Apr-2014, at 11:46 AM EST
From: Tjioe Hian Pin
 
Re: request for advices  
News Group: embarcadero.public.delphi.database.dbexpress
> {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"

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 18-May-2014, at 5:39 PM EST
From: Linden ROTH