在主单元中,我定义了一个函数,然后由另一种具有适当参数的表单调用:
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”子句之后声明函数,我将无法从其他形式调用它。我真的看不懂:(