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

📄 rm_common.pas

📁 这是一个功能强大
💻 PAS
📖 第 1 页 / 共 4 页
字号:
function RMPageEditorList: TList;
begin
  if FRMPageEditorList = nil then
    FRMPageEditorList := TList.Create;

  Result := FRMPageEditorList;
end;

function RMAddInObjectList: TList;
begin
  if FRMAddInObjectList = nil then
    FRMAddInObjectList := TList.Create;
  Result := FRMAddInObjectList;
end;

function RMExportFilterList: TList;
begin
  if FRMExportFilterList = nil then
    FRMExportFilterList := TList.Create;
  Result := FRMExportFilterList;
end;

function RMToolsList: TList;
begin
  if FRMToolsList = nil then
    FRMToolsList := TList.Create;
  Result := FRMToolsList;
end;

function RMAddIns(index: Integer): TRMAddInObjectInfo;
begin
  Result := TRMAddInObjectInfo(FRMAddInObjectList[index]);
end;

function RMAddInsCount: Integer;
begin
  if FRMAddInObjectList = nil then
    Result := -1
  else
    Result := FRMAddinObjectList.Count;
end;

function RMAddInReportPage(Index: Integer): TRMAddInObjectInfo;
begin
  Result := TRMAddInObjectInfo(FRMAddInReportPageList[index]);
end;

function RMAddInReportPageCount: Integer;
begin
  if FRMAddInReportPageList = nil then
    Result := -1
  else
    Result := FRMAddInReportPageList.Count;
end;

function RMPageEditor(Index: Integer): TRMPageEditorInfo;
begin
  Result := TRMPageEditorInfo(FRMPageEditorList[Index]);
end;

function RMPageEditorCount: Integer;
begin
  if FRMPageEditorList = nil then
    Result := 0
  else
    Result := FRMPageEditorList.Count;
end;

function RMDsgPageButton(Index: Integer): TRMToolsInfo;
begin
  Result := TRMToolsInfo(FRMDsgPageButtonList[Index]);
end;

function RMDsgPageButtonCount: Integer;
begin
  if FRMDsgPageButtonList = nil then
    Result := 0
  else
    Result := FRMDsgPageButtonList.Count;
end;

function RMFilters(index: Integer): TRMExportFilterInfo;
begin
  Result := TRMExportFilterInfo(FRMExportFilterList[index]);
end;

function RMFiltersCount: Integer;
begin
  if FRMExportFilterList = nil then
    Result := -1
  else
    Result := FRMExportFilterList.Count;
end;

function RMTools(index: Integer): TRMToolsInfo;
begin
  Result := TRMToolsInfo(FRMToolsList[index]);
end;

function RMToolsCount: Integer;
begin
  if FRMToolsList = nil then
    Result := -1
  else
    Result := FRMToolsList.Count;
end;

function RMFunctionList: TList;
begin
  if FRMFunctionList = nil then
    FRMFunctionList := TList.Create;
  Result := FRMFunctionList;
end;

function RMAddInFunctionCount: Integer;
begin
  if FRMFunctionList <> nil then
    Result := FRMFunctionList.Count
  else
    Result := 0;
end;

function RMAddInFunctions(Index: Integer): TRMCustomFunctionLibrary;
begin
  if (Index >= 0) and (Index < RMFunctionList.Count) then
    Result := TRMCustomFunctionLibrary(FRMFunctionList[Index])
  else
    Result := nil;
end;

procedure RMRegisterComAdapter(aClassRef: TClass; aComAdapterClass: TRMPersistentCompAdapterClass);
var
  tmp: TRMPageEditorInfo;
begin
  tmp := TRMPageEditorInfo.Create(aClassRef, aComAdapterClass);
  RMComAdapterList.Add(tmp);
end;

{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}

constructor TRMPageEditorInfo.Create(aPageClass: TClass; aPageEditorClass: TClass);
begin
  inherited Create;

  FPageClass := aPageClass;
  FPageEditorClass := aPageEditorClass;
end;

procedure RMRegisterPageEditor(aClassRef, aPageEditorClass: TClass);
var
  tmp: TRMPageEditorInfo;
begin
  tmp := TRMPageEditorInfo.Create(aClassRef, aPageEditorClass);
  RMPageEditorList.Add(tmp);
end;

procedure RMRegisterPageButton(const Hint: string; const ButtonBmpRes: string;
  aIsReportPage: Boolean; aPageClass: string);
var
  tmp: TRMToolsInfo;
begin
  tmp := TRMToolsInfo.Create(Hint, ButtonBmpRes, nil);
  tmp.FIsReportPage := aIsReportPage;
  tmp.FPageClassName := aPageClass;

  if FRMDsgPageButtonList = nil then
    FRMDsgPageButtonList := TList.Create;

  FRMDsgPageButtonList.Add(tmp);
end;

procedure RMResigerReportPageClass(ClassRef: TClass);
var
  tmp: TRMAddinObjectInfo;
begin
  tmp := TRMAddinObjectInfo.Create(ClassRef, nil, '', '', False);

  if FRMAddinReportPageList = nil then
    FRMAddinReportPageList := TList.Create;

  FRMAddinReportPageList.Add(tmp);
end;

{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMAddInObjectInfo}

constructor TRMAddInObjectInfo.Create(AClassRef: TClass;
  AEditorFormClass: TFormClass; const AButtonBmpRes: string;
  const AButtonHint: string; AIsControl: Boolean);
begin
  inherited Create;
  FClassRef := TRMClass(AClassRef);
  FEditorFormClass := AEditorFormClass;
  FButtonBmpRes := AButtonBmpRes;
  FButtonHint := AButtonHint;
  FIsControl := AIsControl;
  FPage := '';
  FIsPage := True;
end;

{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMExportFilterInfo}

constructor TRMExportFilterInfo.Create(AClassRef: TRMCustomExportFilter;
  const AFilterDesc: string; const AFilterExt: string);
begin
  inherited Create;
  FFilter := AClassRef;
  FFilterDesc := AFilterDesc;
  FFilterExt := AFilterExt;
end;

{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMToolsInfo}

constructor TRMToolsInfo.Create(const ACaption: string;
  const AButtonBmpRes: string; AOnClick: TNotifyEvent);
begin
  inherited Create;
  FCaption := ACaption;
  FButtonBmpRes := AButtonBmpRes;
  FOnClick := AOnClick;
end;

{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMFunctionSplitter}

constructor TRMFunctionSplitter.Create(aMatchFuncs, aSplitTo: TWideStringList;
  aVariables: TRMVariables);
begin
  inherited Create;
  FParser := TRMParser.Create;
  FMatchFuncs := aMatchFuncs;
  FSplitTo := aSplitTo;
  FVariables := aVariables;
end;

destructor TRMFunctionSplitter.Destroy;
begin
  FParser.Free;
  inherited Destroy;
end;

procedure TRMFunctionSplitter.Split(aStr: WideString);
var
  i, k: Integer;
  s1: WideString;
  lParams: array[0..10] of Variant;
begin
  i := 1;
  aStr := Trim(aStr);
  if (Length(aStr) > 0) and (aStr[1] = '''') then Exit;

  while i <= Length(aStr) do
  begin
    k := i;
    if aStr[1] = '[' then
    begin
      s1 := RMGetBrackedVariable(aStr, k, i);
      if FVariables.IndexOf(s1) <> -1 then
        s1 := FVariables[s1];
      Split(s1);
      k := i + 1;
    end
    else
    begin
      s1 := FParser.GetIdentify(aStr, k);
      if aStr[k] = '(' then
      begin
        FParser.GetParameters(aStr, k, lParams);
        Split(lParams[0]);
        Split(lParams[1]);
        Split(lParams[2]);
        if FMatchFuncs.IndexOf(s1) <> -1 then
          FSplitTo.Add(Copy(aStr, i, k - i));
      end
      else if FVariables.IndexOf(s1) <> -1 then
      begin
        s1 := FVariables[s1];
        Split(s1);
      end
      else if RMWideCharIn(aStr[k], [' ', #13, '+', '-', '*', '/', '>', '<', '=']) then
        Inc(k)
      else if s1 = '' then
        Break;
    end;
    i := k;
  end;
end;


{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{登记注册一个Add-in Object}

procedure RMRegisterObjectByRes(ClassRef: TClass; const ButtonBmpRes: string;
  const ButtonHint: string; EditorFormClass: TFormClass);
var
  tmp: TRMAddinObjectInfo;
begin
  tmp := TRMAddinObjectInfo.Create(ClassRef, EditorFormClass, ButtonBmpRes, ButtonHint,
    False);
  RMAddinObjectList.Add(tmp);
end;

procedure RMRegisterControl(ClassRef: TClass; const ButtonBmpRes, ButtonHint: string);
var
  tmp: TRMAddinObjectInfo;
begin
  tmp := TRMAddinObjectInfo.Create(ClassRef, nil, ButtonBmpRes, ButtonHint, TRUE);
  RMAddinObjectList.Add(tmp);
end;

function _FindRegisteredControl(aPage: string): Boolean;
var
  i: Integer;
  lInfo: TRMAddInObjectInfo;
begin
  Result := False;
  for i := 0 to RMAddinsCount - 1 do
  begin
    lInfo := RMAddins(i);
    if lInfo.IsPage and RMCmp(lInfo.Page, aPage) then
    begin
      Result := True;
      Exit;
    end;
  end;
end;

procedure RMRegisterControl(const aPage, aPageButtonBmpRes: string; aIsControl: Boolean;
  aClassRef: TClass; aButtonBmpRes, aButtonHint: string);
var
  tmp: TRMAddinObjectInfo;
begin
  if not _FindRegisteredControl(aPage) then
  begin
    tmp := TRMAddinObjectInfo.Create(nil, nil, aPageButtonBmpRes,
      '', aIsControl);
    tmp.Page := aPage;
    tmp.IsPage := True;
    RMAddinObjectList.Add(tmp);
  end;

  tmp := TRMAddinObjectInfo.Create(aClassRef, nil, aButtonBmpRes,
    aButtonHint, aIsControl);
  tmp.Page := aPage;
  tmp.IsPage := False;
  RMAddinObjectList.Add(tmp);
end;

procedure RMRegisterControls(const aPage, aPageButtonBmpRes: string;
  aIsControl: Boolean;
  AryClassRef: array of TClass;
  AryButtonBmpRes: array of string;
  AryButtonHint: array of string);
var
  tmp: TRMAddinObjectInfo;
  i: Integer;
begin
  if not _FindRegisteredControl(aPage) then
  begin
    tmp := TRMAddinObjectInfo.Create(nil, nil, aPageButtonBmpRes,
      '', aIsControl);
    tmp.Page := aPage;
    tmp.IsPage := True;
    RMAddinObjectList.Add(tmp);
  end;

  for i := Low(AryClassRef) to High(AryClassRef) do
  begin
    tmp := TRMAddinObjectInfo.Create(AryClassRef[i], nil, AryButtonBmpRes[i],
      AryButtonHint[i], aIsControl);
    tmp.Page := aPage;
    tmp.IsPage := False;
    RMAddinObjectList.Add(tmp);
  end;
end;

{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{登记注册一个Export}

procedure RMRegisterExportFilter(Filter: TRMCustomExportFilter; const FilterDesc, FilterExt: string);
var
  i: Integer;
  tmp: TRMExportFilterInfo;
begin
  for i := 0 to RMFiltersCount - 1 do
  begin
    if RMFilters(i).Filter.ClassName = Filter.ClassName then Exit;
  end;
  tmp := TRMExportFilterInfo.Create(Filter, FilterDesc, FilterExt);
  RMExportFilterList.Add(tmp);
end;

procedure RMUnRegisterExportFilter(Filter: TRMCustomExportFilter);
var
  i: Integer;
begin
  if FRMExportFilterList = nil then Exit;

  for i := 0 to RMFiltersCount - 1 do
  begin
    if RMFilters(i).Filter.ClassName = Filter.ClassName then
    begin
      TRMExportFilterInfo(RMExportFilterList[i]).Free;
      RMExportFilterList.Delete(i);
      Break;
    end;
  end;
end;

{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{登记注册一个Design Tools}

procedure RMRegisterTool(const MenuCaption: string; const ButtonBmpRes: string; OnClick: TNotifyEvent);
var
  tmp: TRMToolsInfo;
begin
  tmp := TRMToolsInfo.Create(MenuCaption, ButtonBmpRes, OnClick);
  RMToolsList.Add(tmp);
end;

procedure RMUnRegisterTool(const MenuCaption: string);
var
  i: Integer;
begin
  if FRMToolsList = nil then Exit;

  for i := 0 to RMToolsList.Count - 1 do
  begin
    if TRMToolsInfo(RMToolsList[i]).Caption = MenuCaption then
    begin
      TRMToolsInfo(RMToolsList[i]).Free;
      RMToolsList.Delete(i);
      Break;
    end;
  end;
end;

{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}

procedure RMRegisterFunctionLibrary(ClassRef: TClass);
var

⌨️ 快捷键说明

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