Bingo To: Multiple recipients of list delphi <[EMAIL PROTECTED]> Send reply to: [EMAIL PROTECTED] From: "Neven MacEwan" <[EMAIL PROTECTED]> Subject: Re: [DUG]: Adding Calculated Field Date sent: Mon, 16 Jun 2003 15:38:33 +1200
> Rohit > > This is interesting, obviously the query 'prepare' and the open/ > close cycle on the table read enough metadata for you to regen the Fields > > N > > ----- Original Message ----- > From: "Rohit Gupta" <[EMAIL PROTECTED]> > To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]> > Sent: Monday, June 16, 2003 10:30 AM > Subject: Re: [DUG]: Adding Calculated Field > > > > Neven, > > > > I have actually got it working... the critical bit (which is why it didnt > > work before) was the sequence and the fact that you have to create > > all the fields. > > > > for qry > > > > prepare > > fielddefs.update > > create the new fielddef > > create all fields from fielddefs > > modify own field to make calculated > > open > > > > for tbl > > > > open > > close > > fielddefs.update > > create the new fielddef > > create all fields from fielddefs > > modify own field to make calculated > > open > > > > To: Multiple recipients of list delphi > > <[EMAIL PROTECTED]> > > Send reply to: [EMAIL PROTECTED] > > From: "Neven MacEwan" <[EMAIL PROTECTED]> > > Subject: Re: [DUG]: Adding Calculated Field > > Date sent: Fri, 13 Jun 2003 13:46:03 +1200 > > > > > Rohit > > > > > > To Create a single field you have to create all the fields, so you > > > can either use the IDE to create a persistant field defs as per your > query > > > (I used to hate this in d5 because if a field changed in size the whole > > > thing would spit) > > > and then before you open the table programtically create your calc field > > > (as per the link I posted) or in your case as the query is dynamic you > have > > > to > > > make all the fielddefs to match your query (see sample code below) > > > > > > The biggest problem with this is getting the metadata for the Field you > > > need to create (I manage this with a 'MetaEntity') but I'm sure you can > come > > > up with > > > a solution. > > > > > > Does this make sense? > > > > > > Neven > > > > > > > > > procedure TmwkMemTable.MakeFields(var Fields: TmwkStringArray); > > > var > > > i: integer; > > > Field: TField; > > > FieldClass: TFieldClass; > > > FieldType: TFieldType; > > > MetaColumn: TmwkMetaColumn; > > > begin > > > Self.FieldDefs.Clear; > > > Self.Fields.Clear; > > > for i := low(Fields) to high(Fields) do > > > begin > > > MetaColumn := MetaEntity.ColumnByName(Fields[i]); > > > if MetaColumn = nil then Continue; > > > FieldType := MetaColumn.FieldType; > > > FieldClass := Self.GetFieldClass(FieldType); > > > if not assigned(FieldClass) then begin > > > Fields[i] := ''; > > > continue; > > > end; > > > Field := FieldClass.Create(Self); > > > if not assigned(Field) then break; > > > Field.FieldName := Fields[i]; > > > Field.FieldKind := fkData; > > > if MetaColumn.DataSize <> 0 then Field.Size := MetaColumn.DataSize; > > > Field.DataSet := Self; > > > Field.Name := Self.Name+Field.FieldName; > > > Self.FieldDefs.Add(Field.Name,FieldType,MetaColumn.DataSize,False); > > > end; > > > end; > > > > > > ----- Original Message ----- > > > From: "Rohit Gupta" <[EMAIL PROTECTED]> > > > To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]> > > > Sent: Friday, June 13, 2003 12:16 PM > > > Subject: Re: [DUG]: Adding Calculated Field > > > > > > > > > > I did some web searches and found scores of people with the same > > > > problem.... some with an identical requirement to me. Amidst the > > > > hundreds of rplies, I think I have a solution - I am about to create a > > > > test app. > > > > > > > > To: Multiple recipients of list delphi > > > > <[EMAIL PROTECTED]> > > > > Send reply to: [EMAIL PROTECTED] > > > > From: "Nello Sestini" <[EMAIL PROTECTED]> > > > > Subject: Re: [DUG]: Adding Calculated Field > > > > Date sent: Fri, 13 Jun 2003 06:50:20 +0700 > > > > > > > > > if you aren't using persistent fields then ISTR you can't > > > > > define calculated fields. > > > > > > > > > > is it possible to pre-define a few of these calculated > > > > > checkboxes (all handled by the same handler) and alter > > > > > their grid visibility on the fly instead of creating them? > > > > > > > > > > (i don't completely understand your problem so this may > > > > > be a miss) > > > > > > > > > > > > > > > -ns > > > > > http://www.roserox.co.th > > > > > > > > > > ----- Original Message ----- > > > > > From: "Rohit Gupta" <[EMAIL PROTECTED]> > > > > > To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]> > > > > > Sent: Friday, June 13, 2003 04:36 > > > > > Subject: Re: [DUG]: Adding Calculated Field > > > > > > > > > > > > > > > > Any other suggestions.. I am really stuck here... > > > > > > > > > > > > > > > > > > PROBLEM > > > > > > > > > > > > The only solution I have is to use a calculated field at run-time. > I > > > cant > > > > > define > > > > > > persistent fields as the query changes depending on user input. > The > > > list > > > > > from the qry > > > > > > gets displayed and the user needs to deselect some rows. > > > > > > > > > > > > If I have a calculated field linked to a checkbox - then when he > > > presses > > > > > space or dbl- > > > > > > clicks on that column, I can fire a separate qry to record this in > an > > > > > exclusion table.... > > > > > > and because its a calculated field I can refresh the display to > give > > > him > > > > > immediate > > > > > > feedback. if the exclusion table was joined to the query then I > would > > > > > have to refresh > > > > > > the query which can take several minutes I would not be able to > > > provide > > > > > immediate > > > > > > feedback. > > > > > > > > > > > > The only other soultion would have been multiple inserts from an > sql > > > > > statement - but > > > > > > that is not supported. Then I could have populated an inclusion > table > > > > > instead. > > > > > > > > > > > > > How do I go about adding a calculated field to a dataset/grid at > > > > > run-time ? I > > > > > > > have tried various things - none of them work > > > > > > > > > > > > > > fielddefs.add > > > > > > > fielddefs.addfielddef > > > > > > > fields.add > > > > > > > Regards > > > > Regards > > > > > > > > Regards > > > > Rohit > > > > ==================================================== > > ================== > > CFL - Computer Fanatics Ltd. 21 Barry's Point Road, AKL, New > > Zealand > > PH (649) 489-2280 > > FX (649) 489-2290 > > email [EMAIL PROTECTED] or [EMAIL PROTECTED] > > ==================================================== > > ================== > > > > -------------------------------------------------------------------------- > - > > New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] > > Website: http://www.delphi.org.nz > > To UnSub, send email to: [EMAIL PROTECTED] > > with body of "unsubscribe delphi" > > Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/ > > > > > > --------------------------------------------------------------------------- > New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] > Website: http://www.delphi.org.nz > To UnSub, send email to: [EMAIL PROTECTED] > with body of "unsubscribe delphi" > Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/ > Regards Rohit ==================================================== ================== CFL - Computer Fanatics Ltd. 21 Barry's Point Road, AKL, New Zealand PH (649) 489-2280 FX (649) 489-2290 email [EMAIL PROTECTED] or [EMAIL PROTECTED] ==================================================== ================== --------------------------------------------------------------------------- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi" Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
