an other SCAR notepad, lol
i wanted to learn about filemenus, and saving to files, so i decided to make a little SCAR notepad :p it might not be usefull, and basic, but i feel like i'v learned a good amount from this, and its some-what cool ;)
thanks to Da 0wner, he helped me on msn, although hes bant :)
he also told me to post the notepad here lol
SCAR Code:
program New;
var
// Initform variables.
EndInitform : Boolean;
notepad : TForm;
Memo1 : TMemo;
Button1, Button2, Button3 : TButton;
OpenDialog1 : TOpenDialog;
SaveDialog1 : TSaveDialog;
filemenu : TMainMenu;
Title, Title1, Option : TMenuItem;
procedure LoadFile(sender: TObject);
begin
OpenDialog1 := TOpenDialog.Create(notepad);
OpenDialog1.InitialDir := AppPath;
OpenDialog1.Options := [ofFileMustExist, ofReadOnly];
OpenDialog1.Filter := 'Text Documents (*.txt)|*.txt|' +
'All Files|*|';
if(OpenDialog1.Execute)then
begin
LoadFromFile(Memo1, OpenDialog1.FileName);
end else
WriteLn('User pressed cancel!');
OpenDialog1.Free;
end;
procedure SaveFile(sender: TObject);
begin
SaveDialog1 := TSaveDialog.Create(nil);
SaveDialog1.InitialDir := AppPath;
SaveDialog1.Filter := 'Text Documents (*.txt)|*.txt|' +
'All Files|*|';
if SaveDialog1.Execute then
savetoFile(Memo1, Savedialog1.FileName);
SaveDialog1.Free;
end;
procedure clear(sender : tobject);
begin
memo1.text:= '';
end;
procedure InitformOnClose(Sender : TObject; var Action : TCloseAction);
begin
if (not(notepad.ModalResult = 1)) then
EndInitform := True;
end;
procedure Initform;
var
TimeInitform : Integer;
hotkey : TMenuAutoFlag;
begin
TimeInitform := GetSystemTime;
notepad := CreateForm;
with notepad do
begin
OnClose := @InitformOnClose;
Position := poScreenCenter;
BorderStyle := bsSingle;
BorderIcons := [biMinimize,biSystemMenu];
ClientWidth := 600;
ClientHeight := 600;
Caption := 'Akwardsaw''s Note Pad';
Color := clblack;
Font.Color := clWindowText;
Font.Height := -11;
Font.Name := 'MS Sans Serif';
Font.Style := [];
PixelsPerInch := 96;
end;
Memo1 := TMemo.Create(notepad);
with Memo1 do
begin
Parent := notepad;
Left := 2;
Top := 2;
Width := 596;
Height := 578;
Memo1.ScrollBars := ssVertical;
with Lines do
begin
Add('Memo1');
end;
text:= '';
TabOrder := 8;
end;
FileMenu := TMainMenu.Create(notepad);
Title := TMenuItem.Create(notepad);
Title.Caption := 'File';
FileMenu.Items.Add(Title);
Option := TMenuItem.Create(notepad);
Option.Caption := 'Clear';
Option.OnClick := @clear;
FileMenu.Items.Items[0].Add(Option);
Option := TMenuItem.Create(notepad);
Option.Caption := 'Load';
Option.OnClick := @LoadFile;
FileMenu.Items.Items[0].Add(Option);
Option := TMenuItem.Create(notepad);
Option.Caption := 'Save';
Option.OnClick := @SaveFile;
FileMenu.Items.Items[0].Add(Option);
WriteLn('Initform compiled in ' + IntToStr(GetSystemTime - TimeInitform) + ' milliseconds!');
end;
procedure SafeInitform;
var
v : TVariantArray;
begin
SetArrayLength(v, 0);
ThreadSafeCall('Initform', v);
end;
procedure ShowInitformModal;
begin
notepad.ShowModal;
end;
procedure SafeShowInitformModal;
var
v : TVariantArray;
begin
SetArrayLength(v, 0);
ThreadSafeCall('ShowInitformModal', v);
end;
procedure MainInitform;
begin
try
SafeInitform;
SafeShowInitformModal;
finally
FreeForm(notepad);
except
WriteLn('An error seems to have occurred in: Initform');
end;
end;
begin
ClearDebug;
GetSelf.WindowState := wsMinimized;
MainInitform;
GetSelf.WindowState := wsNormal;
if (EndInitform) then
TerminateScript;
end.
ima try to add an edit menu later, if you guys think i should :p