超级难题,请问在delphi语言里跟c语言中extern 等价的词是什么?

解决方案 »

  1.   

    Delphi Language Reference
    External declarationsTopic Groups See AlsoThe external directive, which replaces the block in a procedure or function declaration, allows you to call routines that are compiled separately from your program. External routines can come from object files or dynamically loadable libraries.When importing a C function that takes a variable number of parameters, use the varargs directive. For example,function printf(Format: PChar): Integer; cdecl; varargs;The varargs directive works only with external routines and only with the cdecl calling convention.Linking to object filesTo call routines from a separately compiled object file, first link the object file to your application using the $L (or $LINK) compiler directive. For example,On Windows: {$L BLOCK.OBJ}On Linux:   {$L block.o}links BLOCK.OBJ (Windows) or block.o (Linux) into the program or unit in which it occurs. Next, declare the functions and procedures that you want to call:procedure MoveWord(var Source, Dest; Count: Integer); external;
    procedure FillWord(var Dest; Data: Integer; Count: Integer); external;Now you can call the MoveWord and FillWord routines from BLOCK.OBJ (Windows) or block.o (Linux).Declarations like the ones above are frequently used to access external routines written in assembly language. You can also place assembly-language routines directly in your Delphi source code; for more information, see Inline assembler code.Importing functions from librariesTo import routines from a dynamically loadable library (.so or .DLL), attach a directive of the form external stringConstant;to the end of a normal procedure or function header, where stringConstant is the name of the library file in single quotation s. For example, on Windowsfunction SomeFunction(S: string): string; external 'strlib.dll';imports a function called SomeFunction from strlib.dll.On Linux,function SomeFunction(S: string): string; external 'strlib.so';imports a function called SomeFunction from strlib.so.You can import a routine under a different name from the one it has in the library. If you do this, specify the original name in the external directive: external stringConstant1 name stringConstant2;where the first stringConstant gives the name of the library file and the second stringConstant is the routine's original name. On Windows:  The following declaration imports a function from user32.dll (part of the Windows API).function MessageBox(HWnd: Integer; Text, Caption: PChar; Flags: Integer): Integer;   stdcall; external 'user32.dll' name 'MessageBoxA'; The function's original name is MessageBoxA, but it is imported as MessageBox.Instead of a name, you can use a number to identify the routine you want to import:external stringConstant index integerConstant; where integerConstant is the routine's index in the export table.On Linux:  The following declaration imports a standard system function from libc.so.6.function OpenFile(const PathName: PChar; Flags: Integer): Integer; cdecl;   external 'libc.so.6' name 'open'; The function's original name is open, but it is imported as OpenFile.
    In your importing declaration, be sure to match the exact spelling and case of the routine's name. Later, when you call the imported routine, the name is case-insensitive.For more information about libraries, see Libraries and packages.
      

  2.   

    我不是问这个,我举个例子吧  extern int i;请问翻译成delphi怎么写?