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

📄 bthreadeditors.pas

📁 Tread Component for Delphi
💻 PAS
📖 第 1 页 / 共 3 页
字号:
    // If there is only one edit view, then it is clear that
    // the first one is the current edit view
    Result := 0;
  end
  else
  begin
    EditorFileName := UpperCase(ExtractFileName(EditorIntf.FileName));
    WindowIterator := GetWindow(GetDesktopWindow, GW_CHILD);
    // Iterate over all windows whose owner is the Desktop
    WindowIterator := GetWindow(WindowIterator, GW_HWNDNEXT);
    // If we find a window with the class name "TEditWindow"
    // and the filenames match then this is the currently active
    // edit view
    while (WindowIterator <> 0) and IsWindow(WindowIterator) do
    begin
      if GetClassName(WindowIterator, Buffer, SizeOf(Buffer) - 1) = 0 then
        RaiseLastWin32Error;
      if StrPos(Buffer, 'TEditWindow') <> nil then
      begin
        if GetWindowText(WindowIterator, Buffer, SizeOf(Buffer) - 1) = 0 then
          RaiseLastWin32Error;
        StrUpper(Buffer);
        if StrPos(Buffer, PChar(EditorFileName)) <> nil then
        begin
          // I the case where there are multiple edit windows
          // open the first one you come to in the iteration process
          // should always be the top-most (or most recently active) edit
          // window - JCH
          // Scan window caption from the end; if we started at the
          // beginning, we might run into the colon of C:\MyFile
          APos := StrRScan(Buffer, ':');
          Inc(APos);
          Result := StrToIntDef(StrPas(APos), -1);
          // Subtract 1 since we need 0..GetViewCount-1 rather than 1..GetViewCount
          if Result <> -1 then
            Dec(Result);
          Break;
        end;
      end;
      WindowIterator := GetWindow(WindowIterator, GW_HWNDNEXT);
    end;
  end;
end;

procedure TEventsEditorNotification.FileNotification(NotifyCode: TFileNotification; const FileName: string; var Cancel: Boolean);
begin
  if ((NotifyCode = fnProjectClosing) or (NotifyCode = fnFileClosing)) then
    begin
    if( Assigned(FOnCloseNotify)) then
      FOnCloseNotify( NIL );
      
    end

  else
    if (Assigned(FOnUpdateNotify)) then
      FOnUpdateNotify(NIL);

end;

procedure TEventsEditorNotification.EventNotification(NotifyCode: TEventNotification; var Cancel: Boolean);
begin
  if (Assigned(FOnUpdateNotify)) then
      FOnUpdateNotify(NIL);
end;
{$ENDIF}

{ TEmptyEntryPropertyEditor }

function TEmptyEntryPropertyEditor.GetValue: string;
begin
  Result := 'Edit...';
end;

procedure TEmptyEntryPropertyEditor.Edit;
begin
  if (DesignForm = nil) then
    DesignForm := TSynchroMethodsForm.Create(nil, Designer);
    
  DesignForm.SetDesigner(Designer);
  DesignForm.Show();
end;

function TEmptyEntryPropertyEditor.GetAttributes: TPropertyAttributes;
begin
  Result := [paDialog, paReadOnly];
end;

{ TBThreadControlEditor }

{
destructor TBThreadControlEditor.Destroy;
begin
  if (DesignForm <> nil) then
    begin
    DesignForm.Free;
    DesignForm := nil;
    end;
  inherited;
end;
}

procedure TBThreadControlEditor.Edit;
begin
  if (DesignForm = nil) then
    DesignForm := TSynchroMethodsForm.Create(nil, Designer);
    
  DesignForm.SetDesigner(Designer);
  DesignForm.UpdateView();
  DesignForm.Show();
end;

procedure TBThreadControlEditor.ExecuteVerb(Index: Integer);
begin
  case (Index) of
    0: GenerateEvent(Designer, GetTypeData(TypeInfo(TBThreadSynchroNotifyEvent)), 'SynchroFunc');
    1: GenerateEvent(Designer, GetTypeData(TypeInfo(TBThreadSynchroDataNotifyEvent)), 'SynchroFuncData');
  else
    Edit();
  end;
end;

function TBThreadControlEditor.GetVerb(Index: Integer): string;
begin
  case (Index) of
    0: Result := 'New S.M. No Data';
    1: Result := 'New S.M. + Data';
  else
    Result := 'Edit S.M. ...';
  end;
end;

function TBThreadControlEditor.GetVerbCount(): Integer;
begin
  Result := 3;
end;

{ TSynchroMethodsForm }

constructor TSynchroMethodsForm.Create(AOwner: TComponent; _Designer: IFormDesigner);
{$IFDEF D9}
var
  Services : IOTAServices;
{$ENDIF}
begin
  inherited Create(AOwner);
  Designer := _Designer;
  UpdateNotifier := TEventsEditorNotification.Create;
{$IFDEF D9}
  Services := (BorlandIDEServices as IOTAServices);
  IDENotifierID := Services.AddNotifier( UpdateNotifier );
{$ELSE}
  ToolServices.AddNotifierEx(UpdateNotifier);
{$ENDIF}
//  UpdateNotifier.FOnFileNotify := OnFileNotify;
  UpdateNotifier.FOnUpdateNotify := OnUpdateNotify;
  UpdateNotifier.FOnCloseNotify := OnCloseNotify;
  ThreadEventsList := TStringList.Create;
  StdEventsList := TStringList.Create;
  ValidateComponents;
end;

destructor TSynchroMethodsForm.Destroy;
{$IFDEF D9}
var
  Services : IOTAServices;
{$ENDIF}
begin
  ThreadEventsListView.OnChange := nil;
  StdEventsListView.OnChange := nil;
  ClearLists;
  StdEventsList.Free;
  ThreadEventsList.Free;
{$IFDEF D9}
  Services := (BorlandIDEServices as IOTAServices);
  Services.RemoveNotifier( IDENotifierID );
{$ELSE}
  ToolServices.RemoveNotifier(UpdateNotifier);
  UpdateNotifier.Free;
{$ENDIF}
  inherited;
end;

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

procedure TSynchroMethodsForm.ClearLists;
var
  I: Integer;
begin
  for I := 0 to ThreadEventsList.Count - 1 do
    ThreadEventsList.Objects[I].Free;
  // delete ((TThreadEventSruct *)ThreadEventsList.Objects [ I ] );
  ThreadEventsList.Clear();
  StdEventsList.Clear();
end;

procedure TSynchroMethodsForm.SetDesigner(_Designer: IFormDesigner);
begin
  Designer := _Designer;
  if (Designer <> nil) then
    UpdateView();
end;

procedure TSynchroMethodsForm.OnUpdateNotify(Sender : TObject);
begin
  DesignForm.UpdateView;
end;

procedure TSynchroMethodsForm.OnCloseNotify(Sender : TObject);
begin
  Designer := NIL;
  Hide();
end;

procedure TSynchroMethodsForm.UpdateView;
var
  OldOnChange: TLVChangeEvent;
  Updated: Boolean;
  I: Integer;
  J: Integer;
  Found: Boolean;
  Item: TListItem;
  Struct: TThreadEventSruct;
begin
  if (Designer = nil) then
    Exit;
  ClearLists;
  //  if ( PageControl.ActivePage == ThreadSynchroTabSheet )
  //  PropInfo := GetPropInfo ( __typeinfo(TBMSynchroEventsEditorHelperClass), "ThreadNotifyEventEmptyEvent" );
  Designer.GetMethods(GetTypeData(TypeInfo(TBThreadSynchroNotifyEvent)), AddMethodNoDataEntry);
  //  PropInfo = GetPropInfo ( __typeinfo(TBMSynchroEventsEditorHelperClass), "ThreadDataNotifyEventEmptyEvent" );
  Designer.GetMethods(GetTypeData(TypeInfo(TBThreadSynchroDataNotifyEvent)), AddMethodDataEntry);
  //  PropInfo = ::GetPropInfo ( __typeinfo(TButton), "OnClick" );
  Designer.GetMethods(GetTypeData(TypeInfo(TNotifyEvent)), AddStandardNotifyEntry);
  //  ThreadEventsListView.Items.Clear ();
  OldOnChange := ThreadEventsListView.OnChange;
  ThreadEventsListView.OnChange := nil;
  Updated := false;
  I := 0;
  while I < ThreadEventsListView.Items.Count do
  begin
    Found := false;
    for J := 0 to ThreadEventsList.Count - 1 do
    begin
      if (ThreadEventsListView.Items.Item[I].Caption = ThreadEventsList.Strings[J]) then
      begin
        if (ThreadEventsListView.Items.Item[I].SubItems.Strings[0] = TThreadEventSruct(ThreadEventsList.Objects[J]).Parameter) then
        begin
          Found := true;
          // delete ((TThreadEventSruct *)ThreadEventsList.Objects [ J ]);
          ThreadEventsList.Objects[J].Free;
          ThreadEventsList.Delete(J);
          break;
        end;
      end;
    end;
    if (not Found) then
    begin
      if (not Updated) then
        ThreadEventsListView.Items.BeginUpdate();
      Updated := true;
      ThreadEventsListView.Items.Item[I].Free;
      Dec(I);
    end;
    Inc(I);
  end;
  for I := 0 to ThreadEventsList.Count - 1 do
  begin
    Item := ThreadEventsListView.Items.Add();
    Item.Caption := ThreadEventsList.Strings[I];
    Struct := (ThreadEventsList.Objects[I]) as TThreadEventSruct;
    Item.SubItems.Add(Struct.Parameter);
    Item.SubItems.Add(Struct.CallingFormat);
  end;
  ThreadEventsListView.OnChange := OldOnChange;
  if (Updated) then
    ThreadEventsListView.Items.EndUpdate();
  Updated := false;
  //  StdEventsListView.Items.Clear ();
  OldOnChange := StdEventsListView.OnChange;
  StdEventsListView.OnChange := nil;
  I := 0;
  while I < StdEventsListView.Items.Count do //  for ( int I := 0; I < StdEventsListView.Items.Count; I ++ )
  begin
    Found := false;
    for J := 0 to StdEventsList.Count - 1 do
    begin
      if (StdEventsListView.Items.Item[I].Caption = StdEventsList.Strings[J]) then
      begin
        Found := true;
        StdEventsList.Delete(J);
        break;
      end;
    end;
    if (not Found) then
    begin
      if (not Updated) then
        StdEventsListView.Items.BeginUpdate();
      Updated := true;
      StdEventsListView.Items.Item[I].Free;
      Dec(I);
    end;
    Inc(I);
  end;
  for I := 0 to StdEventsList.Count - 1 do
  begin
    Item := StdEventsListView.Items.Add();
    Item.Caption := StdEventsList.Strings[I];
    Item.SubItems.Add('TObject *Sender');
    Item.SubItems.Add('');
  end;
  StdEventsListView.OnChange := OldOnChange;
  if (Updated) then
    StdEventsListView.Items.EndUpdate();
  ValidateComponents;
end;

procedure TSynchroMethodsForm.ValidateComponents;
begin
  if (PageControl.ActivePage = ThreadSynchroTabSheet) then
    ActiveListView := ThreadEventsListView
  else
    ActiveListView := StdEventsListView;
  ShowButton1.Enabled := (ActiveListView.ItemFocused <> nil);
  ShowButton2.Enabled := (ActiveListView.ItemFocused <> nil);
  RenameButton1.Enabled := ShowButton1.Enabled;
  RenameButton2.Enabled := ShowButton1.Enabled;
  GenCallButton1.Enabled := ShowButton1.Enabled;
  GenCallButton2.Enabled := ShowButton1.Enabled;
  CopyCallButton1.Enabled := ShowButton1.Enabled;
  CopyCallButton2.Enabled := ShowButton1.Enabled;
  //  CreateGroupBox.Visible := ( TabControl.TabIndex = 0 );
  //  RenameButton.Visible := CreateGroupBox.Visible;
  if (ActiveListView.ItemFocused <> nil) then
    StatusBar.SimpleText := 'Thread.Synchronize ( ' + ActiveListView.ItemFocused.Caption + ActiveListView.ItemFocused.SubItems.Strings[1] + ' );'
  else
    StatusBar.SimpleText := '';
end;

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

procedure TSynchroMethodsForm.BtnNoDataEventClick(Sender: TObject);
begin
  if (Designer = nil) then Exit;

⌨️ 快捷键说明

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