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

📄 bthreadeditors.pas

📁 Tread Component for Delphi
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  AddMethodNoDataItem(GenerateEvent(Designer, GetTypeData(TypeInfo(TBThreadSynchroNotifyEvent)), 'SynchroFunc')).EditCaption();
  FormResize(Sender);
end;

procedure TSynchroMethodsForm.BtnDataEventClick(Sender: TObject);
begin
  if (Designer = nil) then Exit;
  AddMethodDataItem(GenerateEvent(Designer, GetTypeData(TypeInfo(TBThreadSynchroDataNotifyEvent)), 'SynchroFuncData')).EditCaption();
  FormResize(Sender);
end;

procedure TSynchroMethodsForm.RenameButton1Click(Sender: TObject);
begin
  if (ActiveListView.ItemFocused <> nil) then
  begin
    ActiveListView.ItemFocused.EditCaption();
  end;
end;

procedure TSynchroMethodsForm.ShowButton1Click(Sender: TObject);
begin
  if (Designer = nil) then Exit;
  if (ActiveListView.ItemFocused <> nil) then
  begin
    Designer.ShowMethod(ActiveListView.ItemFocused.Caption);
  end;
  Show();
end;

procedure TSynchroMethodsForm.CopyCallButton1Click(Sender: TObject);
begin
  Clipboard.AsText := StatusBar.SimpleText;
end;

{$IFDEF D9}
procedure TSynchroMethodsForm.GenCallButton1Click(Sender: TObject);
var
  I: Integer;
  ModuleServices: IOTAModuleServices;
  Module: IOTAModule;
  EditorIntf: IOTAEditor;
  Editor: IOTASourceEditor;
  CurrentView: Integer;
  View: IOTAEditView;
  CharPos: TOTACharPos;
  EditPos: TOTAEditPos;
  OldBlockType: TOTABlockType;
  Writer: IOTAEditWriter;
begin
//  ModIntf := ToolServices.GetModuleInterface(ToolServices.GetCurrentFile());
  ModuleServices := BorlandIDEServices as IOTAModuleServices;
  Module := ModuleServices.CurrentModule;

  if (Module = nil) then
  begin
    ShowMessage(
      'Please select the editor bofore pressing this button.'#13 +
      'For now the code will go to the clipboard.'#13 +
      'You can paste wherever you want.'
      );
    Clipboard().AsText := StatusBar.SimpleText;
  end
  else
  begin
//    Module.Show();
//    ModIntf.ShowSource();

    // Get the interface to the source editor.
    for I := 0 to Module.GetModuleFileCount-1 do
    begin
      EditorIntf := Module.GetModuleFileEditor(I);
      if( EditorIntf.QueryInterface(IOTASourceEditor, Editor) = S_OK ) then
        Break;
        
    end;

    // If the file is not a source file, Editor is nil.
    if Editor = nil then
      Exit;

    begin
      if (Editor.EditViewCount > 0) then
      begin
        Editor.Show();
        CurrentView := GetCurrentEditView(Editor);
        View := Editor.EditViews[ CurrentView ];
        if (View <> nil) then
        begin
          try
            begin
              EditPos := View.CursorPos;
              View.ConvertPos(true, EditPos, CharPos);
              OldBlockType := Editor.BlockType;
              Editor.BlockType := btInclusive;
              Editor.BlockStart := CharPos;
              Editor.BlockAfter := CharPos;
              Editor.BlockVisible := True;
              if (MessageDlg('Insert the code at this location ?', mtConfirmation, [mbYes, mbNo], 0) = mrYes) then
              begin
                Writer := Editor.CreateUndoableWriter();
                try
                  begin
                    Writer.CopyTo(View.CharPosToPos(CharPos));
                    if ((CharPos.CharIndex = 0) and (EditPos.Col > 0)) then
                      for I := 0 to EditPos.Col - 2 do
                        Writer.Insert(' ');
                    Writer.Insert(PChar(StatusBar.SimpleText));
                    Writer.Insert(#13#10);
                    for I := 0 to EditPos.Col - 1 do
                      Writer.Insert(' ');
                    Writer.CopyTo(MaxLongint);
                  end;
                finally
                  Writer := NIL;
                end;
                Editor.Show();
                Inc(EditPos.Line);
                View.CursorPos := EditPos;
              end;
              Editor.BlockType := OldBlockType;
              Editor.BlockStart := CharPos;
              Editor.BlockAfter := CharPos;
              Editor.BlockVisible := False;
            end;
          except;
          end;
//          View.Free();
        end;
      end;
//      EditorIntf.Free();
    end;
//    ModIntf.Free();
  end;
end;

{$ELSE}

procedure TSynchroMethodsForm.GenCallButton1Click(Sender: TObject);
var
  I: Integer;
  ModIntf: TIModuleInterface;
  EditorIntf: TIEditorInterface;
  CurrentView: Integer;
  View: TIEditView;
  CharPos: TCharPos;
  EditPos: TEditPos;
  OldBlockType: TBlockType;
  Writer: TIEditWriter;
begin
  ModIntf := ToolServices.GetModuleInterface(ToolServices.GetCurrentFile());
  if (ModIntf = nil) then
  begin
    ShowMessage(
      'Please select the editor bofore pressing this button.'#13 +
      'For now the code will go to the clipboard.'#13 +
      'You can paste wherever you want.'
      );
    Clipboard().AsText := StatusBar.SimpleText;
  end
  else
  begin
    ModIntf.ShowSource();
    EditorIntf := ModIntf.GetEditorInterface();
    if (EditorIntf <> nil) then
    begin
      if (EditorIntf.GetViewCount() > 0) then
      begin
        CurrentView := GetCurrentEditView(EditorIntf);
        View := EditorIntf.GetView(CurrentView);
        if (View <> nil) then
        begin
          try
            begin
              EditPos := View.CursorPos;
              View.ConvertPos(true, EditPos, CharPos);
              OldBlockType := EditorIntf.BlockType;
              EditorIntf.BlockType := btInclusive;
              EditorIntf.BlockStart := CharPos;
              EditorIntf.BlockAfter := CharPos;
              EditorIntf.BlockVisible := true;
              if (MessageDlg('Insert the code at this location ?', mtConfirmation, [mbYes, mbNo], 0) = mrYes) then
              begin
                Writer := EditorIntf.CreateUndoableWriter();
                try
                  begin
                    Writer.CopyTo(View.CharPosToPos(CharPos));
                    if ((CharPos.CharIndex = 0) and (EditPos.Col > 0)) then
                      for I := 0 to EditPos.Col - 2 do
                        Writer.Insert(' ');
                    Writer.Insert(PChar(StatusBar.SimpleText));
                    Writer.Insert(#13#10);
                    for I := 0 to EditPos.Col - 1 do
                      Writer.Insert(' ');
                    Writer.CopyTo(MaxLongint);
                  end;
                finally
                  Writer.Free();
                end;
                ModIntf.ShowSource();
                Inc(EditPos.Line);
                View.CursorPos := EditPos;
              end;
              EditorIntf.BlockType := OldBlockType;
              EditorIntf.BlockStart := CharPos;
              EditorIntf.BlockAfter := CharPos;
              EditorIntf.BlockVisible := false;
            end;
          except;
          end;
          View.Free();
        end;
      end;
      EditorIntf.Free();
    end;
    ModIntf.Free();
  end;
end;

{$ENDIF}
procedure TSynchroMethodsForm.NewStdButtonClick(Sender: TObject);
begin
  if (Designer = nil) then
    Exit;
  AddStandardNotifyItem(GenerateEvent(Designer, GetTypeData(TypeInfo(TNotifyEvent)), 'NotifyEvent')).EditCaption();
  FormResize(Sender);
end;

procedure TSynchroMethodsForm.ThreadEventsListViewChange(Sender: TObject;
  Item: TListItem; Change: TItemChange);
begin
  ValidateComponents();
end;

procedure TSynchroMethodsForm.ThreadEventsListViewEdited(Sender: TObject;
  Item: TListItem; var S: string);
begin
  if (Designer = nil) then
    Exit;
  if (Item.Caption <> S) then
  begin
    if (Designer.MethodExists(S)) then
    begin
      S := GenerateEventName(Designer, S);
    end;
    Designer.RenameMethod(Item.Caption, S);
  end;
end;

procedure TSynchroMethodsForm.ThreadEventsListViewKeyPress(Sender: TObject;
  var Key: Char);
begin
  if ((Key = #13) or (Key = ' ')) then
    ShowButton1Click(Sender);
end;

procedure TSynchroMethodsForm.FormResize(Sender: TObject);
begin
  ThreadEventsListView.Column[1].Width := ThreadEventsListView.ClientWidth - ThreadEventsListView.Column[0].Width;
  StdEventsListView.Column[1].Width := StdEventsListView.ClientWidth - StdEventsListView.Column[0].Width;
end;

procedure TSynchroMethodsForm.FormShow(Sender: TObject);
begin
  FormResize(Sender);
  ValidateComponents;
end;

procedure TSynchroMethodsForm.AddMethodNoDataEntry(const S: string);
var
  Struct: TThreadEventSruct;
begin
  Struct := TThreadEventSruct.Create;
  Struct.Parameter := 'Thread : TBExecuteThread';
  ThreadEventsList.AddObject(S, Struct);
end;

procedure TSynchroMethodsForm.AddMethodDataEntry(const S: string);
var
  Struct: TThreadEventSruct;
begin
  Struct := TThreadEventSruct.Create;
  Struct.Parameter := 'Thread : TBExecuteThread; var Data : Pointer';
  Struct.CallingFormat := ', [%Data to pass here]';
  ThreadEventsList.AddObject(S, Struct);
end;

procedure TSynchroMethodsForm.AddStandardNotifyEntry(const S: string);
begin
  StdEventsList.Add(S);
end;

function TSynchroMethodsForm.AddMethodNoDataItem(const S: string): TListItem;
var
  Item: TListItem;
begin
  Item := ThreadEventsListView.Items.Add();
  Item.Caption := S;
  Item.SubItems.Add('Thread : TBExecuteThread');
  Item.SubItems.Add('');
  Result := Item;
end;

function TSynchroMethodsForm.AddMethodDataItem(const S: string): TListItem;
var
  Item: TListItem;
begin
  Item := ThreadEventsListView.Items.Add();
  Item.Caption := S;
  Item.SubItems.Add('Thread : TBExecuteThread; var Data : Pointer');
  Item.SubItems.Add(', & [%Data to pass here]');
  Result := Item;
end;

function TSynchroMethodsForm.AddStandardNotifyItem(const S: string): TListItem;
var
  Item: TListItem;
begin
  Item := StdEventsListView.Items.Add();
  Item.Caption := S;
  Item.SubItems.Add('Sender : TObject');
  Item.SubItems.Add('');
  Result := Item;
end;

procedure TSynchroMethodsForm.Timer1Timer(Sender: TObject);
begin
  UpdateView;
  ValidateComponents;
end;

procedure Register;
begin
  RegisterComponents('Threads', [TBThread, TBThreadGroup]);
  RegisterPropertyEditor(TypeInfo(TPersistent), TBThread, 'SynchroMethods', TEmptyEntryPropertyEditor);
  RegisterComponentEditor(TBThread, TBThreadControlEditor);
end;

initialization
  DesignForm := nil;
finalization
  if (DesignForm <> nil) then
    begin
    DesignForm.Free;
    DesignForm := nil;
    end;
    
end.

⌨️ 快捷键说明

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