View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0001825 | JEDI VCL | 00 JVCL Components | public | 2004-06-01 22:11 | 2004-08-03 07:37 |
Reporter | puyd | Assigned To | obones | ||
Priority | normal | Severity | feature | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Product Version | |||||
Target Version | Fixed in Version | ||||
Summary | 0001825: TJvgExportDataset can't excute when the DataSet use dynamically allocated field components. | ||||
Description | If DataSet use dynamically allocated field components( the property DataSet.DefaultFields=True ), TJvgExportDataset.Excute will be failed. The errormessage is 'Fieldname missing'. Because at the JvgExportComponents line 595,the function name is 'procedure TJvgExportDataset.Execute',code is 'Dest.FieldDefs.Add(DataSet.Fields[I].Name, FieldType, DataSet.Fields[I].Size, DataSet.Fields[I].Required)', if DataSet use dynamically allocated field components,the 'DataSet.Fields[I].Name' is Empty.May be it will be changed by 'DataSet.Fields[I].FieldName'. | ||||
Additional Information | Sorry,I'm from China and my English is too pool. :-( | ||||
Tags | No tags attached. | ||||
|
By the way.If use this mothed to export dataset.It can't work when the fieldname of source dataset is not same with the destination dataset.Are there any mothed to resolve this matter? |
|
Have you tried changing Fields[i].Name to Fields[i].FieldName? Does it work? To copy from one dataset to another with different fieldnames, you can either use their filed indices (if they match up) or some kind of mapping method where you specify the name of the source field and the name of the matching dest field, i.e: ID=Ident Name=UserName Adress=Location etc You would then have to write a method that retrieves the dest name from the source name and copies the field. I don't think there are any ready made components for that except possibly TBatchMove (standard Delphi BDE). There aren't in JVCL anyway (AFAIK) |
|
This is my code: procedure TJvgExportDataset.Execute; var I, RecNo, RecCount: Integer; Dest: TDataset; AllowExportRecord: Boolean; FieldType: TFieldType; begin inherited Execute; Dest := nil; if Assigned(FOnCreateDest) then FOnCreateDest(Self, Dest); if Dest = nil then Exit; Dest.Close; for I := 0 to DataSet.FieldCount - 1 do begin FieldType := DataSet.Fields[I].DataType; if FieldType = ftAutoInc then FieldType := ftInteger; // delete this line will support dynamically generated field components. (* Dest.FieldDefs.Add(DataSet.Fields[I].FieldName, FieldType, DataSet.Fields[I].Size, DataSet.Fields[I].Required); *) end; Dest.Open; try DataSet.First; RecCount := DataSet.RecordCount; RecNo := 0; while not DataSet.EOF do begin AllowExportRecord := True; if Assigned(FOnExportRecord) then FOnExportRecord(Self, DataSet, AllowExportRecord); if AllowExportRecord then begin Dest.Append; for I := 0 to DataSet.FieldCount - 1 do if DataSet.Fields[I].DataType in [ftString, ftMemo] then Dest.Fields[I].Value := GetFieldValue(DataSet.Fields[I]) else Dest.Fields[I].Value := DataSet.Fields[I].Value; Dest.Post; end; DoProgress(0, RecCount, RecNo, ''); Inc(RecNo); DataSet.Next; end; DoProgress(0, RecCount, RecCount, ''); if Assigned(FOnSaveDest) then FOnSaveDest(Self, Dest); finally Dest.Close; FreeAndNil(Dest); end; end; edited on: 06-03-04 19:59 |
|
An other question: At the last of these code, after the Dest DataSet Close, why must to FreeAndNil(dest)? I think,free the Dest is not a good idea. Because when Export is done,I will use the Dest DataSet at next time. |
|
> why must to FreeAndNil(dest)? A minor change can prevent this: if Assigned(FOnSaveDest) then FOnSaveDest(Self, Dest); finally if Dest <> nil then Dest.Close; FreeAndNil(Dest); end; Now, if you set Dest := nil in your OnSaveDest handler, the dataset is not freed and you can reuse it as may times as you like. |
|
Why not just check if the fields are the defaults or not, i.e: ... for I := 0 to DataSet.FieldCount - 1 do begin FieldType := DataSet.Fields[I].DataType; if FieldType = ftAutoInc then FieldType := ftInteger; if not DataSet.DefaultFields then Dest.FieldDefs.Add(DataSet.Fields[I].Name, FieldType, DataSet.Fields[I].Size, DataSet.Fields[I].Required); end; ... edited on: 06-10-04 02:04 |
|
The fix has been added to CVS, so please try it out. |
|
This bug has not had any activity for more than a month, it is therefore considered fixed. To the original poster: If you think the issue is still there, even after having tested with the JVCL3, please create a new bug report. To get the latest JCL and JVCL please go to these sites: http://jcl.sf.net/daily/ http://jvcl.sf.net/daily/ |
Date Modified | Username | Field | Change |
---|---|---|---|
2004-06-01 22:11 | puyd | New Issue | |
2004-06-01 22:22 | puyd | Note Added: 0004429 | |
2004-06-03 01:14 |
|
Note Added: 0004446 | |
2004-06-03 06:40 |
|
Status | new => feedback |
2004-06-03 19:55 | puyd | Note Added: 0004455 | |
2004-06-03 19:59 | puyd | Note Edited: 0004455 | |
2004-06-03 20:56 | puyd | Note Added: 0004456 | |
2004-06-10 01:58 |
|
Note Added: 0004527 | |
2004-06-10 02:04 |
|
Note Added: 0004528 | |
2004-06-10 02:04 |
|
Note Edited: 0004528 | |
2004-06-15 06:19 |
|
Note Added: 0004560 | |
2004-08-03 07:37 | obones | Status | feedback => resolved |
2004-08-03 07:37 | obones | Resolution | open => fixed |
2004-08-03 07:37 | obones | Assigned To | => obones |
2004-08-03 07:37 | obones | Note Added: 0004898 |