From: <ob...@us...> - 2006-06-27 13:00:45
|
Revision: 10749 Author: obones Date: 2006-06-27 05:59:08 -0700 (Tue, 27 Jun 2006) ViewCVS: http://svn.sourceforge.net/jvcl/?rev=10749&view=rev Log Message: ----------- Mantis 3568: Now uses the OnGetText event to retrieve the field value Modified Paths: -------------- trunk/jvcl/run/JvDBGridExport.pas Modified: trunk/jvcl/run/JvDBGridExport.pas =================================================================== --- trunk/jvcl/run/JvDBGridExport.pas 2006-06-27 12:50:38 UTC (rev 10748) +++ trunk/jvcl/run/JvDBGridExport.pas 2006-06-27 12:59:08 UTC (rev 10749) @@ -86,6 +86,8 @@ FLastExceptionMessage: string; FSilent: Boolean; FOnException: TNotifyEvent; + FUseFieldGetText: boolean; + procedure SetUseFieldGetText(const Value: boolean); procedure CheckVisibleColumn; protected procedure HandleException; @@ -95,12 +97,14 @@ procedure DoSave; virtual; procedure DoClose; virtual; abstract; procedure Notification(AComponent: TComponent; Operation: TOperation); override; + function GetFieldValue(const Field: TField): string; public constructor Create(AOwner: TComponent); override; function ExportGrid: Boolean; published // (p3) these should be published: all exporters must support them property Caption: string read FCaption write FCaption; + property UseFieldGetText:boolean read FUseFieldGetText write SetUseFieldGetText default False; property Grid: TDBGrid read FGrid write FGrid; property FileName: TFileName read FFileName write FFileName; property Silent: Boolean read FSilent write FSilent default True; @@ -249,7 +253,7 @@ {$IFDEF UNITVERSIONING} const UnitVersioning: TUnitVersionInfo = ( - RCSfile: '$URL$'; + RCSfile: '$RCSfile: JvDBGridExport.pas,v $'; Revision: '$Revision$'; Date: '$Date$'; LogPath: 'JVCL\run' @@ -330,6 +334,19 @@ DoClose; end; +function TJvCustomDBGridExport.GetFieldValue(const Field: TField): string; +begin + if Assigned(Field.OnGetText) and FUseFieldGetText then + begin + Result := ''; + Field.OnGetText(Field, Result, True); + end + else + begin + Result := string(Field.Value); + end; +end; + procedure TJvCustomDBGridExport.HandleException; begin if ExceptObject <> nil then @@ -352,6 +369,11 @@ Grid := nil; end; +procedure TJvCustomDBGridExport.SetUseFieldGetText(const Value: boolean); +begin + FUseFieldGetText := Value; +end; + //=== { TJvDBGridWordExport } ================================================ constructor TJvDBGridWordExport.Create(AOwner: TComponent); @@ -449,7 +471,7 @@ begin if FRecordColumns[I].Exportable and not FRecordColumns[I].Field.IsNull then try - lTable.Cell(J, K).Range.InsertAfter(string(FRecordColumns[I].Field.Value)); + lTable.Cell(J, K).Range.InsertAfter(GetFieldValue(FRecordColumns[I].Field)); except Result := False; HandleException; @@ -609,8 +631,7 @@ begin lCell := lTable.Range[IndexFieldToExcel(K) + IntToStr(J)]; try - // Do not cast with string ! - lCell.Value := FRecordColumns[I].Field.Value; + lCell.Value := GetFieldValue(FRecordColumns[I].Field); except Result := False; HandleException; @@ -885,7 +906,7 @@ begin if Exportable and not Field.IsNull then try - lText := Field.AsString; + lText := GetFieldValue(Field); if lText = '' then lText := ' '; except @@ -1018,7 +1039,7 @@ try if not FRecordColumns[I].Field.IsNull then begin - lField := FRecordColumns[I].Field.AsString; + lField := GetFieldValue(FRecordColumns[I].Field); if (Pos(Separator, lField) <> 0) or (FQuoteEveryTime) then lString := lString + AnsiQuotedStr(lField, '"') else @@ -1148,14 +1169,12 @@ for I := 0 to FColumnCount - 1 do if FRecordColumns[I].Exportable then try - with FRecordColumns[I] do - Properties.Add(ColumnName, Field.AsString); + Properties.Add(FRecordColumns[I].ColumnName, GetFieldValue(FRecordColumns[I].Field)); except Result := False; HandleException; end; end; - Next; Inc(ARecNo); if not DoProgress(0, lRecCount, ARecNo, Caption) then This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |