tags:

views:

163

answers:

1

I have an EXCEL sheets witgh various

C:\Documents and Settings\delfi\MilkDataMgr\FtsExcel.pas(2056):Undeclared identifier: smrBgm167GallonsGrosssDA'

procedure convertXSLToDelfi(fuel: TFtsFuelTypes; const prefix: string);
var
ColumnNameMap  : TStrings;
i              : Integer;
other          : string;
begin

   { ColumnNameMap  := TStrings; }
   ColumnNameMap  := TStringList.Create;
   ColumnNameMap.Values['smrBgm229GallonsGross']:=' smrBgm167GallonsGrosssDA';
   i := ColumnNameMap.IndexOfName(smrBgm229GallonsGross);
     if i >= 0 then
     smrBgm229GallonsGross:= ColumnNameMap.Values[smrBgm229GallonsGross]
     else
     smrBgm229GallonsGross:= smrBgm229GallonsGross;
end;

a detailed issue is in this link, i folowed the solution offered there http://stackoverflow.com/questions/1460297/how-to-create-delphi-4-structure-to-map-column-names-in-xls-to-column-names-in-sq

I am just picking up threads kindly help me out.

+1  A: 

In the code I gave you, notice that the value inside the brackets for the Values property was quoted. It's a string. Maybe you meant to have "smrBgm229GallonsGross" in quotes, too, like this:

ColumnNameMap.Values['smrBgm229GallonsGross'] := 'smrBgm167GallonsGrosssDA';

In your code, the compiler complains that it doesn't recognize the identifier smrBgm229GallonsGross. Look at your code. Have you declared such an identifier? If not, then you can't expect the compiler to know what you're asking of it, and the error message makes perfect sense.

(If you were using Perl, the compiler might have known what you wanted. There are certain situations where a so-called "bareword" will be interpreted as a string literal rather than an identifier. But that's Perl, not Delphi.)

So far, I've only been looking at the first line of code that mentions smrBgm229GallonsGross. However, there are five more lines of code, where you look up the index of the name and then assign values to a variable, and those will need a proper declaration of a variable. In my example, I used the made-up variable name ColumnName to represent the name of whatever input column you happen to be processing at the time. I assumed you would be iterating over a list of columns in a loop, so you would do the same thing for each column, taking a value from your Excel spreadsheet and transferring it into a corresponding column in the database, which was represented by the also-made-up variable name RealColumnName.

Rob Kennedy
you are right Rob , it is undefined in the Procedure i created.
vas
Further I coded it as "ColumnNameMap.Values 'smrBgm229GallonsGross'] := 'smrBgm167GallonsGrosssDA'; I made a type up here. "
vas
I correced the Typo....Also I have commented { ColumnNameMap := TStrings; }I was getting an error "[Error] smrXcel.pas(2251): Incompatible types: 'TStrings' and 'Class reference'" at the place.where as in your code it is included.Is that OK?
vas
There shouldn't have been any typos to correct. You should **copy and paste** your **real code**. Anyway, please look more carefully at my code. You will see that *nowhere* did I attempt to assign a class reference to any variable. Are you confusing declarations and assignment statements?
Rob Kennedy
I will do as you tol me .
vas
There is only one Column that has issue 'Bgm167GrosGalnsDA' Real column name (existing in the EXCEL sheet) ;
vas
'smrBgm229GallonsGross' name i have to assign in Delphi (as per pre-existing columns i.e smrBgm167GallonsGross/smrBgm133GallonsGross)
vas
What do you mean only one column has an issue? You've mentioned a few columns that need to be translated. I no longer understand what your problem is.
Rob Kennedy
I am sorry sir, the columns smrBgm167GallonsGross and smrBgm133GallonsGross " are pre-existing and are matched accordingly in the EXCEL sheets ...so there is no hitch in extracing the data
vas
On the other hand 'Bgm167GrosGalnsDA'(beginning) is named 'Bgm167GrosGalnsDA'in EXCEL, and needs to be NAMED'smrBgm229GallonsGross' in the DELPHI code.
vas
Related to the above,'Egm167GrosGalnsDA'(ending) is named 'Egm167GrosGalnsDA' in EXCEL, and needs to be NAMED'smrEgm229GallonsGross' in the DELPHI code.
vas
OK. So set up mappings for those two pairs of names. You realize that a string list or a dictionary can hold multiple pairs of names, right? If there is no mapping configured, then the code I've shown will simply use the original name instead. Again, I really don't understand what problem you're having anymore.
Rob Kennedy
i am sorry to not make the PROBLEM clear..I will edit the above Question
vas