View Issue Details

IDProjectCategoryView StatusLast Update
0003915JEDI VCL00 JVCL Componentspublic2007-01-04 05:33
ReporterZENsanAssigned Toobones 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product VersionDaily / GIT 
Target VersionFixed in Version3.30 
Summary0003915: TJvCustomDBGridExport.GetFieldValue crashes export DoExport function
DescriptionTJvCustomDBGridExport.GetFieldValue crashes export DoExport function.
Also there is one moment:

  Result := True; //!!! Here result id true
  FRunningInstance := True;
  try
    // get running instance
    FWord := GetActiveOleObject(cWordApplication);
  except
    FRunningInstance := False;
    try
      // create new
      FWord := CreateOleObject(cWordApplication);
    except
      FWord := Unassigned;
      HandleException;
// raise EJvExportDBGridException.Create(RsNoWordApplication);
    end;
  end;

  if VarIsEmpty(FWord) then
    Exit;//!!!And here need to set Result to false

This moment is in all DoExport functions.
Additional InformationAnd the second problem is that it will be better to replace GetFieldValue with this function:
function TJvCustomDBGridExport.GetFieldValue(const Field: TField): Widestring;
begin
  if Assigned(Field.OnGetText) and FUseFieldGetText then
  begin
    Result := '';
    Field.OnGetText(Field, Result, True);
  end
  else
  begin
    Result := Field.AsWidestring;
    {Here was Field.Value, but there will be error if Fiels is ftWideMemo or Another field that is ancestor of TMemoField}Conversion to Widestring is more safe - and more usefull, because in Word and Excel we will not lose any Unicde data}
  end;
end;
TagsNo tags attached.

Activities

ZENsan

2006-09-20 03:04

reporter   ~0010148

Where Field.AsWidestring is better to select type of field..
Only when FieldType<>ftInteger,ftFloat...

ZENsan

2006-09-26 00:47

reporter   ~0010177

This variant of implmenetation I think is better, because when exporting columns into excel - numbers are not stored as text.

function TJvCustomDBGridExport.GetFieldValue(const Field: TField): Variant;
var
  Str: String;
begin
  if Assigned(Field.OnGetText) and FUseFieldGetText then
  begin
    Result := '';
    Field.OnGetText(Field, Str, True);
    Result := Str;
  end
  else
    Result := Field.Value;
end;

2006-09-26 00:51

 

JvDBGridExport.zip (7,803 bytes)

ZENsan

2006-09-26 06:22

reporter   ~0010183

In uploaded source there is some correction of DoExport function. Beacause in the begining Result=True and then after program determines that Word or Excel is not available - There was an Exit, but not Result := False and then Exit..

obones

2006-09-26 06:27

administrator   ~0010184

Please provide a patch file, it makes integration easier.

ZENsan

2006-09-26 06:37

reporter   ~0010185

Last edited: 2006-09-26 06:42

Can you tel me some Windows utility to generate patch file?
Code Fusion 3.0, PatchWise 3.28 I think is not good for this..

obones

2006-09-26 06:52

administrator   ~0010186

http://homepages.borland.com/jedi/wiki/index.php?title=Create_a_patch_file

And if you are not already using TortoiseSVN:

http://homepages.borland.com/jedi/wiki/index.php?title=Repository

2006-09-26 07:19

 

JvDBGridExport_patch.zip (22,512 bytes)

obones

2006-09-29 06:51

administrator   ~0010242

Does not look like you used the method described in the wiki, with TortoiseSVN, the patch file is not in the correct format and thus unusable.

ZENsan

2006-09-29 08:00

reporter   ~0010254

I have used WinMerge utility.. Ok I will try to install Tortoise SVN

ZENsan

2006-10-05 10:39

reporter   ~0010291

Sorry, but I can't understand how to create patch file with that Tortoise SVN.. I installed it, defined respoitory root and added JVCL folder to it, but how to create atch I don't know. I have no time to investigate this software, because I am very heavy loaded at work :(.

obones

2006-10-06 01:37

administrator   ~0010295

It's all explained in the links I gave you above. Once you have retrieved the repository via Tortoise, creating the patch is as simple as rigthclicking on the file and choosing "Create patch".

2006-10-07 09:25

 

JvDBGridExport.patch (2,050 bytes)
Index: JvDBGridExport.pas
===================================================================
--- JvDBGridExport.pas	(revision 10965)
+++ JvDBGridExport.pas	(working copy)
@@ -97,7 +97,7 @@
     procedure DoSave; virtual;
     procedure DoClose; virtual; abstract;
     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
-    function GetFieldValue(const Field: TField): string;
+    function GetFieldValue(const Field: TField): Variant;
   public
     constructor Create(AOwner: TComponent); override;
     function ExportGrid: Boolean;
@@ -334,17 +334,18 @@
   DoClose;
 end;
 
-function TJvCustomDBGridExport.GetFieldValue(const Field: TField): string;
+function TJvCustomDBGridExport.GetFieldValue(const Field: TField): Variant;
+var
+  Str: String;
 begin
   if Assigned(Field.OnGetText) and FUseFieldGetText then
   begin
     Result := '';
-    Field.OnGetText(Field, Result, True);
+    Field.OnGetText(Field, Str, True);
+    Result := Str;
   end
   else
-  begin
-    Result := VarToStr(Field.Value);
-  end;
+    Result := Field.Value;
 end;
 
 procedure TJvCustomDBGridExport.HandleException;
@@ -422,7 +423,10 @@
   end;
 
   if VarIsEmpty(FWord) then
-    Exit;
+    begin
+      Result := False;
+      Exit;
+    end;
 
   try
     if not FRunningInstance then
@@ -502,6 +506,7 @@
     lTable.UpdateAutoFormat;
   except
     HandleException;
+    Result := False;
   end;
 end;
 
@@ -589,7 +594,10 @@
   end;
 
   if VarIsEmpty(FExcel) then
-    Exit;
+    begin
+      Result := False;
+      Exit;
+    end;
   try
     if not FRunningInstance then
       FExcel.Visible := Visible;
@@ -669,6 +677,7 @@
     end;
   except
     HandleException;
+    Result := False;
   end;
 end;
 
@@ -942,6 +951,7 @@
     end;
   except
     HandleException;
+    Result := False;
   end;
 end;
 
@@ -1072,6 +1082,7 @@
     end;
   except
     HandleException;
+    result := False;
   end;
 end;
 
@@ -1196,6 +1207,7 @@
     end;
   except
     HandleException;
+    Result := False;
   end;
 end;
 
JvDBGridExport.patch (2,050 bytes)

ZENsan

2006-10-07 09:26

reporter   ~0010329

Problem was, because I didn't completed checkout - so Create patch option was unavailable. This patch is with today's checkout.

ZENsan

2006-10-18 10:18

reporter   ~0010372

May be I need to correct something?

obones

2007-01-04 05:32

administrator   ~0010531

Thanks, your patch is now in SVN.
Sorry for the delay.

Issue History

Date Modified Username Field Change
2006-09-19 07:58 ZENsan New Issue
2006-09-20 03:04 ZENsan Note Added: 0010148
2006-09-26 00:47 ZENsan Note Added: 0010177
2006-09-26 00:51 ZENsan File Added: JvDBGridExport.zip
2006-09-26 06:22 ZENsan Note Added: 0010183
2006-09-26 06:27 obones Note Added: 0010184
2006-09-26 06:37 ZENsan Note Added: 0010185
2006-09-26 06:42 ZENsan Note Edited: 0010185
2006-09-26 06:52 obones Note Added: 0010186
2006-09-26 07:19 ZENsan File Added: JvDBGridExport_patch.zip
2006-09-29 06:51 obones Note Added: 0010242
2006-09-29 06:51 obones Status new => feedback
2006-09-29 08:00 ZENsan Note Added: 0010254
2006-10-05 10:39 ZENsan Note Added: 0010291
2006-10-06 01:37 obones Note Added: 0010295
2006-10-07 09:25 ZENsan File Added: JvDBGridExport.patch
2006-10-07 09:26 ZENsan Note Added: 0010329
2006-10-18 10:18 ZENsan Note Added: 0010372
2007-01-04 05:32 obones Status feedback => resolved
2007-01-04 05:32 obones Fixed in Version => Daily / SVN
2007-01-04 05:32 obones Resolution open => fixed
2007-01-04 05:32 obones Assigned To => obones
2007-01-04 05:32 obones Note Added: 0010531