Undeclared identifier:

对着背影说爱祢 提交于 2020-01-16 13:17:09

问题


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 how to create Delphi 4 structure to map column names in XLS to column names in SQL

I am just picking up threads kindly help me out.


回答1:


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.



来源:https://stackoverflow.com/questions/1463181/undeclared-identifier

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!