Re: Макросы
Хаю ду ю ду -=BETA TESTER=-?
Смотрю и вижу, как ты печатаешь умные вещи и дай-ка, думаю,
тоже что-нибудь напечатаю:
BT> Нужно в программе реализовать макросы, посоветуйте компонент.
Например:
1) Компонент TScript Язык скрипта - подмножество Дельфи-паскаля.
2) Innerfuse Pascal Script 2.78
3) MSScriptControl.ScriptControl
Да много всякого - спроси у яндекса
Пример использования MSScriptControl.ScriptControl
unit UnitFormula;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls,ComObj;
type
TFormFormula = class(TForm)
Image1: TImage;
Panel1: TPanel;
GroupBox1: TGroupBox;
Label1: TLabel;
EditFrom: TEdit;
Label2: TLabel;
EditTo: TEdit;
Panel2: TPanel;
EditPhrase: TEdit;
Label3: TLabel;
EditStep: TEdit;
Label4: TLabel;
GroupBox2: TGroupBox;
EditScaleX: TEdit;
Label5: TLabel;
Label7: TLabel;
EditScaleY: TEdit;
GroupBox3: TGroupBox;
Label6: TLabel;
Label8: TLabel;
EditUpY: TEdit;
EditUpX: TEdit;
procedure FormCreate(Sender: TObject);
procedure EditPhraseKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
SC: Variant;
{ Public declarations }
end;
var
FormFormula: TFormFormula;
implementation
{$R *.DFM}
procedure TFormFormula.FormCreate(Sender: TObject);
begin
SC := CreateOleObject('MSScriptControl.ScriptControl');
SC.Language := 'VBScript';
end;
procedure TFormFormula.EditPhraseKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var low, high: integer;
x: extended;
Formula_amper: string;
Formula: string;
y: extended;
step: Extended;
i: integer;
scalex: extended;
scaley: extended;
UpY: integer;
UpX: integer;
begin
if key = VK_RETURN then
begin
low := StrToInt(EditFrom.Text);
high := StrToInt(EditTo.Text);
step := StrToFloat(EditStep.Text);
scalex := StrToFloat(EditScaleX.Text);
scaley := StrToFloat(EditScaleY.Text);
UpY := StrToInt(EditUpY.Text);
UpX := StrToInt(EditUpX.Text);
Formula := EditPhrase.Text;
Formula_amper := '';
for i := 1 to Length(Formula) do
if Formula[i] = 'x'
then Formula_amper := Formula_amper + '(%g)'
else Formula_amper := Formula_amper + Formula[i];
x := low;
Image1.Canvas.Pen.Color := clRed;
Image1.Canvas.FillRect(Image1.ClientRect);
Image1.Canvas.MoveTo( - 1024, Image1.Height - round(UpY {* scaley}));
// ось x
Image1.Canvas.LineTo( 1024, Image1.Height - round(UpY {* scaley}));
Image1.Canvas.MoveTo(round( UpX {* scalex}), - 1024); // ось y
Image1.Canvas.LineTo(round( UpX {* scalex}), 1024);
Image1.Canvas.Pen.Color := clBlack;
Formula := Format(Formula_amper, [x, x, x, x, x, x, x, x, x, x, x, x,
x, x, x, x, x]);
try
y := StrToFloat(SC.Eval(Formula)); // разделитель - точка!!!
except
raise Exception.Create('Ашипка какая-то, наверное в формуле');
end;
Sleep(0);
Image1.Canvas.MoveTo(round(x * scalex + UpX),
Image1.Height - round(y * scaley + UpY)
);
x := x + step;
while (x <= high) and (not Application.Terminated) do
begin
Application.ProcessMessages;
Formula := Format(Formula_amper, [x, x, x, x, x, x, x, x, x, x, x]);
y := StrToFloat(SC.Eval(Formula));
Image1.Canvas.LineTo(round(x * scalex + UpX),
Image1.Height - round(y * scaley + UpY)
);
FormFormula.Caption := FloatToStr(x) + ':' + FloatToStr(y) + ' ' +
IntToStr(round(x * scalex + UpX)) + ':' +
IntToStr(Image1.Height - round(y * scaley
+ UpY));
x := x + step;
end;
end;
end;
end.