⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 common.pas

📁 一个编译器源代码。用法看里面的“使用说明”
💻 PAS
字号:
unit Common;

interface

uses {$IFDEF NOTGUI} SysUtils {$ELSE} SysUtils, Windows, Messages {$ENDIF};

procedure SetLogObject(hWnd: HWND);
procedure SetOnlyMsg;
procedure WriteToScreen(Msg: String);
procedure ShowCompileResult;
function IsNumeric(s: String): Boolean;
function IsVariable(s: String): Boolean;
function HexToInt(Str: String): Integer;

var
  hLog: HWND;
  OnlyMsg: Boolean = False;
  CompileResult: String;

const
  LibEx = '.txt';

implementation

procedure SetLogObject(hWnd: HWND);
begin
  hLog := hWnd;
end;

procedure SetOnlyMsg;
begin
  OnlyMsg := True;
end;

procedure WriteToScreen(Msg: String);
{$IFDEF NOTGUI}
{$ELSE}
var
  Txt: array[0..255] of Char;
{$ENDIF}
begin
  {$IFDEF NOTGUI}
    WriteLn(Msg);
  {$ELSE}
    if OnlyMsg then
    begin
      CompileResult := CompileResult+#13#10+Msg;
    end
    else
    begin
      lstrcpy(Txt,PChar(Msg));
      SendMessage(hLog,LB_ADDSTRING,0,Integer(@Txt));
    end;
  {$ENDIF}
end;

procedure ShowCompileResult;
begin
  MessageBox(HWND_DESKTOP,PChar(CompileResult),'Viking Compiler',MB_ICONINFORMATION);
end;

function IsNum(s: String): Boolean;
var
  Code: Integer;
  Value: Double;
begin
  Val(s,Value,Code);
  Result := (Code = 0);
end;

function IsNumeric(s: String): Boolean;
begin
  result := False;
  if IsNum(s) or (s[1] = '$') then result := True;
end;

function IsVariable(s: String): Boolean;
begin
  Result := (Pos('''',s) = 0);
end;

function HexToInt(Str: String): Integer;
var
  c: integer;
  len: integer;
  ch: char;
begin
  Str:=UpperCase(Str);
  result:=0;
  len:=length(Str);
  for c:=len downto 1 do
  begin
    ch:=Str[c];
    if (ch<='F')and(ch>='A') then
      result:=result+(ord(ch)-55) shl ((len-c) shl 2)
    else if (ch<='9')and(ch>'0') then
      result:=result+(ord(ch)-48) shl ((len-c) shl 2);
  end;
end;

end.
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -