unit RegexBuddyActionClientUnit; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, OleServer, RegexBuddy_TLB, StdCtrls, Spin, ExtCtrls; type TFormActionDemo = class(TForm) RadioKind: TRadioGroup; MemoRegex: TMemo; MemoReplace: TMemo; CheckDotAll: TCheckBox; CheckCaseless: TCheckBox; CheckMultiline: TCheckBox; Label1: TLabel; SpinLimit: TSpinEdit; BtnInvoke: TButton; RegexBuddyConnection: TRegexBuddyIntf; procedure BtnInvokeClick(Sender: TObject); procedure RegexBuddyConnectionFinishAction(ASender: TObject; Action: OleVariant); private Connected: Boolean; public end; var FormActionDemo: TFormActionDemo; implementation {$R *.dfm} procedure TFormActionDemo.BtnInvokeClick(Sender: TObject); begin if not Connected then begin // Connect to RegexBuddy try RegexBuddyConnection.Connect; except on E: Exception do begin Application.MessageBox(PChar('Could not connect to RegexBuddy because of the following error:' + sLineBreak + E.Message + sLineBreak + sLineBreak + 'Make sure that RegexBuddy is installed on your computer, and has been run at least once.'), 'Invoke RegexBuddy', 0); Exit; end end; Connected := True; // Make sure our instance of RegexBuddy makes it clear to the user that we're connected to it RegexBuddyConnection.IndicateApp(Caption, Handle); end; RegexBuddyConnection.InitAction(VarArrayOf([ 1, // Version RadioKind.ItemIndex, MemoRegex.Lines.Text, MemoReplace.Lines.Text, CheckDotAll.Checked, CheckCaseless.Checked, CheckMultiline.Checked, SpinLimit.Value, '' // Description ])); // Bring RegexBuddy to front // SetForegroundWindow only works when the calling thread has input focus // Since we have input focus when the user clicked our button, // it is our job to bring RegexBuddy to front. SetForegroundWindow(RegexBuddyConnection.GetWindowHandle()); end; procedure TFormActionDemo.RegexBuddyConnectionFinishAction(ASender: TObject; Action: OleVariant); begin if Action[0] = 1 then begin // Since we called InitRegex with Action[0] = 1, // FinishRegex will always be called with Action[0] = 1 // But we check just in case RadioKind.ItemIndex := Action[1]; MemoRegex.Lines.Text := Action[2]; MemoReplace.Lines.Text := Action[3]; CheckDotAll.Checked := Action[4]; CheckCaseless.Checked := Action[5]; CheckMultiline.Checked := Action[6]; SpinLimit.Value := Action[7]; end end; end.