Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2005 Nov : NewInstance question

www.cryer.info
Managed Newsgroup Archive

NewInstance question

Subject:NewInstance question
Posted by:"preston" (orac..@xmission.com)
Date:Tue, 15 Nov 2005 14:51:41 -0700

I'm trying to copy fields from one dataset to another at runtime. When
creating calculated fields I have the following:

with targetDS.FieldDefs do
     begin
       newField := field.newInstance as TField;
       with newField do
       begin
         // need to set owner somewhere
         FieldName := field.Name;
         Calculated := True;
         if newField is TFloatField then
           TFloatField(newField).Currency := TFloatField(field).Currency;
         DataSet := targetDS;
         Name := targetDS.Name + FieldName;
         targetDS.FieldDefs.Add(Name, field.dataType, 0, false);
       end;
     end;

I'm using newInstance because I don't want a giant case statement for
each different TField subClass. This works great but I'm concerned that
the owner is not getting set for the new field. Therefore, I'm worrried
that I've introduced a memory leak.

Any suggestions?

Preston

Glossary

Replies:

www.cryer.info
Managed Newsgroup Archive