1

在主单元中,我定义了一个函数,然后由另一种具有适当参数的表单调用:

unit Parser;
interface
uses
[...]

function SaveGridLayoutToReg(ASaveViewName: AnsiString): Integer;

type
TForm1 = class(TForm)
[...]
function SaveGridLayoutToReg(ASaveViewName: AnsiString): Integer;
end;

[...]

function TForm1.SaveGridLayoutToReg(ASaveViewName: AnsiString): Integer;
var
  AStoreKey: string;
  AOptions: TcxGridStorageOptions;
  LayoutRegistryKey: TRegistry;
begin
  AStoreKey := 'Software\KTRT\Stats';

  AOptions := [];
  cxGrid1TableView1.StoreToRegistry(AStoreKey, True, AOptions, ASaveViewName);

  LayoutRegistryKey.RootKey:= HKEY_CURRENT_USER;
  if LayoutRegistryKey.OpenKey(AStoreKey+'\'+ASaveViewName, false) then
    Result := 0
  else
    Result := -1;
end;

另一种形式:

[...]
uses Parser;

procedure TForm3.Button1Click(Sender: TObject);
var
LayoutRegistryKey: TRegistry;
AStoreLocation : AnsiString;
AStoreKey: string;
begin
  AStoreLocation := Edit1.Text;
  if Parser.SaveGridLayoutToReg(AStoreLocation) <> 0 then
    Label1.Visible := True
  else
  begin
    Label1.Visible := False;
    Form3.Visible := False;
  end;
end;
[...]

我在某种程度上做错了,因为我不断收到错误

不满意的转发或外部声明

如果我不在 TForm1 类中声明该函数,则将找不到网格视图。如果我不在“uses”子句之后声明函数,我将无法从其他形式调用它。我真的看不懂:(

4

1 回答 1

5

您在接口部分声明了两个函数,即SaveGridLayoutToReg

function SaveGridLayoutToReg(ASaveViewName: AnsiString): Integer;

TForm1.SaveGridLayoutToReg行之后。但是在实现部分,你只实现后一个。

也就是说,你需要更换

unit Parser;
interface
uses
[...]

function SaveGridLayoutToReg(ASaveViewName: AnsiString): Integer;

type
TForm1 = class(TForm)
[...]
function SaveGridLayoutToReg(ASaveViewName: AnsiString): Integer;
end;

unit Parser;
interface
uses
[...]

type
TForm1 = class(TForm)
[...]
function SaveGridLayoutToReg(ASaveViewName: AnsiString): Integer;
end;

或者你必须实现这两个功能。

于 2012-08-31T08:28:05.303 回答