【高分求助】进来看看。有点麻烦【分不够可以商量】
本人正在做一个汇编的IDE,其中基本框架也做好了(感觉还不错,呵呵,语法高亮,代码完成,自动提示等等)。大伙一定要帮忙啊,此软件事关我的终生幸福(保送,呵呵)
这几天在做资源编辑器,也就是要保证完全和Visual Studio兼容可以读取rc资源脚本文件,保存的rc文件也可以被Visual Studio打开。
今天在写常量管理类(TConstCategory,TCategories),基本上写完了。
其中inc文件有类似如下的固定格式:
;#category:test
;#default:test
;#extensive:test
TEST_1 equ 1H
TEST_2 equ 2H
TEST_3 equ 4H
TEST_ALL equ TEST_1 OR TEST_2 OR TEST_3
当我执行这个代码的时候
var t:TCategories;
begin
t:=TCategories.Create ;
try
t.LoadFromFile(ExtractFilePath(Application.ExeName)+'lxcRes.inc' );
lxcAlert(t.ConstToString(t.StringToConst('TEST_ALL','*'),'*'));
finally
t.Free ;
ExitProcess(0);
end;
结果是 TEST_1 OR TEST_2 OR TEST_3 OR TEST_ALL。使用如何的算法可以不输出TEST_1 OR TEST_2 OR TEST_3这些重复了的常量呢??
附代码(其中lxc开头的都是我自己写的一些实用函数,这个代码中使用到的有:
function lxcTraceBox(args:array of const)用来跟踪lxcTraceBox参数的,在开发环境下会弹出每个参数的值。在EXE中不会弹出
function lxcHashCode(const s:string),得到字符串s的哈西码,用于搜索加速的
function lxcAlert()系列函数有三个重载,类似ShowMessage
function lxcCompressString(const s:string)去掉首位空格,并将连续的制表符和空格替换为1个空格
function lxcIsNumber(s:string;HexStyle:LHexStyle=hsAuto):boolean;判断s是否是数字,支持16进制和10进制,支持Pascal,C,ASM,Basic语法的16进制风格或自动识别
function lxcStrToInt(s:string;HexStyle:LHexStyle=hsAuto):Integer;同上,不过是将字符串转换为数字
procedure lxcSplit(s:string;splitter:char;var st:TStringList;const quote:char=#0);类似TStringList的Delimm属性进行分割字符串,不过功能要强大些
):
unit untResConst;
interface
uses Classes,Windows,SysUtils,StrUtils,untGlobal;
type
PResConst=^TResConst;
{Structure for storing const}
TResConst=record
sName:String[30];
lName:Cardinal;
Value:Cardinal;
end;
//used to manage TConstCategory
TCategories=class;
//a category for a serie of consts
TConstCategory=class
private
FList:TList;
FID:Cardinal;
FName:string;
public
function AddConst(Name:string;Value:Cardinal):integer;
function SeekConst(Name:string):Cardinal;
function IsExist(Name:string):boolean;
procedure Append(Category:TConstcategory);
constructor Create(Name:string);
destructor Free;
//Category ID, for seeking quicker
property ID:Cardinal read FID;
//name for this category
property Name:string read FName;
end;
TCategories=class
private
FCategories:TList;
FDefault:TConstCategory;
FExtensive:TConstCategory;
class function _Hash(s:string):cardinal;
public
function IsExistCategory(Name:string):boolean;
procedure LoadFromFile(const FileName:string);
function SeekCategory(Name:string):TConstCategory;
function SeekConst(Name:string;Category:string):Cardinal;
function ConstToString(Value:Cardinal;Category:string;Extensive:Boolean=false):string;
function StringToConst(Str:String;Category:string;Extensive:Boolean=false):cardinal;
function IsExistConst(Name:string;Category:string):boolean;
property Extensive:TConstCategory read FExtensive;
property Default:TConstCategory read FDefault;
constructor Create;
destructor Free;
end;
implementation
uses lxcGlobal;