home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Programming Unleashed
/
Delphi_Programming_Unleashed_SAMS_Publishing_1995.iso
/
misc
/
explorer
/
main.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1995-03-20
|
13KB
|
479 lines
unit Main;
{ Program copyright (c) 1995 by Charles Calvert & Steve Teixeira }
{ Project Name: EXPLORER }
interface
uses
WinTypes, WinProcs, Classes,
Graphics, Forms, Controls,
Messages, Menus, FileCtrl,
Update, About, MakeCls,
Welcome, Status, Buttons,
StdCtrls, IniFiles, ExtCtrls;
type
TExplore = class(TForm)
ListBox1: TListBox;
ComboBox1: TComboBox;
EUnitName: TEdit;
MainMenu1: TMainMenu;
File1: TMenuItem;
Options1: TMenuItem;
Eye: TBitBtn;
ObjectModel1: TMenuItem;
VCL1: TMenuItem;
OWL1: TMenuItem;
TurboVision1: TMenuItem;
UpdateObjects1: TMenuItem;
Exit1: TMenuItem;
Help1: TMenuItem;
About1: TMenuItem;
Contents1: TMenuItem;
Toolbar: TPanel;
SpeedButton1: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
N1: TMenuItem;
procedure FormDestroy(Sender: TObject);
procedure EyeClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure Options1Click(Sender: TObject);
procedure UpdateObjects1Click(Sender: TObject);
procedure About1Click(Sender: TObject);
procedure VCL1Click(Sender: TObject);
procedure OWL1Click(Sender: TObject);
procedure TurboVision1Click(Sender: TObject);
procedure Contents1Click(Sender: TObject);
procedure ComboBox1KeyPress(Sender: TObject; var Key: Char);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormActivate(Sender: TObject);
private
NewUser: Boolean;
cbBuffer: PChar;
vclPath: String;
bpPath: String;
oePath: String;
ObjectList: String;
TextEditor: String;
ComboId: Word;
SList: TStringList;
procedure ResetUI;
function GetAFile(S: String): String;
function GetAParent(S: String): String;
procedure WMCommand(var Msg: TWMCommand); message wm_Command;
procedure HandleChange;
procedure HandleFileChange;
procedure SelectFirstItem;
end;
var
Explore: TExplore;
implementation
uses
DirStuff, Viewer, SysUtils, ExpIni, Dialogs, StrUtils;
{$R *.DFM}
function GetClass(S: String): String;
begin
Result := GetFirstWord(S);
end;
function TExplore.GetAFile(S: String): String;
var
i: Integer;
Temp: String;
Parent: String;
Total: Integer;
begin
Parent := '';
Total := SList.Count - 1;
for i := 0 to Total do begin
Temp := SList.Strings[i];
if GetFirstWord(Temp) = S then begin
Move(Temp[53], Parent[1], 26);
Parent[0] := Chr(Length(Temp) - 52);
Parent := StripSpaces(Parent);
break;
end;
end;
GetAFile := Parent;
end;
function TExplore.GetAParent(S: String): String;
var
i: Integer;
Temp: String;
Total: Integer;
begin
Result := '';
Total := SList.Count - 1;
for i := 0 to Total do begin
Temp := SList.Strings[i];
if CompareStr(GetFirstWord(Temp), S) = 0 then begin
Move(Temp[27], Result[1], 26);
Result[0] := #26;
Result := StripSpaces(Result);
break;
end;
end;
end;
procedure TExplore.HandleChange;
var
S: String;
i: Integer;
begin
ListBox1.Clear;
S := ComboBox1.Items.Strings[ComboBox1.ItemIndex];
ListBox1.Items.Add(S);
EUnitName.Text := GetAFile(S);
repeat
S := GetAParent(S);
ListBox1.Items.Add(S);
until (S = 'TObject') or (S = '');
end;
procedure TExplore.HandleFileChange;
var
S: String;
begin
S := ListBox1.Items.Strings[ListBox1.ItemIndex];
if S = 'TObject' then
EUnitName.Text := 'SYSTEM.PAS'
else
EUnitName.Text := GetAFile(S);
end;
procedure TExplore.WMCommand(var Msg: TWMCommand);
begin
if Msg.ItemId = ComboId then
if Msg.NotifyCode = lbn_SelChange then
HandleChange;
if Msg.Ctl = ListBox1.Handle then
if Msg.NotifyCode = lbn_SelChange then
HandleFileChange;
inherited;
end;
procedure TExplore.FormDestroy(Sender: TObject);
begin
IniFile.WriteString('SETTINGS', 'CurrObject', ObjectList);
IniFile.WriteInteger('SETTINGS', 'XPos', Left);
IniFile.WriteInteger('SETTINGS', 'YPos', Top);
FreeMem(cbBuffer, 256);
IniFile.Free;
SList.Free;
end;
procedure TExplore.EyeClick(Sender: TObject);
var
Path: String;
S: String;
A: array[0..255] of char;
WERetVal: word;
begin
if Listbox1.ItemIndex < 0 then
Listbox1.ItemIndex := 0;
ListBox1.SetFocus;
FileViewer.Edit1.Text := ListBox1.Items.Strings[ListBox1.ItemIndex];
if FileViewer.Edit1.Text = '' then
FileViewer.Edit1.Text := ListBox1.Items.Strings[0];
if ObjectList = 'delobj.lst' then begin
S := UpperCase(EUnitName.Text);
if (S = 'EXCEPTS.PAS') or (S = 'SYSTEM.PAS') or (S = 'SYSUTILS.PAS') then
Path := vclPath + 'rtl\sys\'
else if (S = 'CALENDAR.PAS') or (S = 'COLORGRD.PAS') or (S = 'DIROUTLN.PAS')
or (S = 'GAUGES.PAS') or (S = 'SPIN.PAS') then
Path := vclPath + 'samples\'
else
Path := vclPath + 'vcl\';
end
else if ObjectList = 'owlobj.lst' then
Path := bpPath+'owl\'
else if ObjectList = 'tvobj.lst' then begin
if (S = 'OBJECTS.PAS') or (S = 'VALIDATE.PAS') then
Path := bpPath+'common\'
else
Path := bpPath+'tv\';
end;
S := Path + S;
if not FileExists(S) then
MessageDlg('Can''t find file, Run Options', mtError, [mbOk], 0)
else try
FileViewer.ListBox1.Items.LoadFromFile(S);
FileViewer.FileName := S;
FileViewer.Show;
except
on E:EOutOfResources do begin
if MessageDlg('File to large for Viewer. Load into text editor?',
mtError, [mbYes, mbNo], 0) = mrYes then begin
StrPCopy(A, TextEditor + ' ' + S);
WERetVal := WinExec(A, sw_ShowNormal);
if WERetVal < 32 then
MessageDlg('Couldn''t spawn editor. Error code: ' +
IntToStr(WERetVal), mtError, [mbOk], 0);
end;
end;
end;
end;
procedure TExplore.FormCreate(Sender: TObject);
procedure GetoePath;
var
S : String;
i : Integer;
begin
S := ParamStr(0);
i := integer(S[0]);
while S[i] <> '\' do
begin
dec(S[0]);
dec(i);
end;
oePath := S;
end;
const
Size = 128;
var
P: array[0..Size] of Char;
i: Integer;
S : String;
H: Hwnd;
begin
GetMem(cbBuffer, 256);
Left := IniFile.ReadInteger('SETTINGS', 'XPos', Left);
Top := IniFile.ReadInteger('SETTINGS', 'YPos', Top);
Toolbar.ShowHint := IniFile.ReadBool('SETTINGS', 'BubbleHelp', True);
vclPath := AddBackSlash(IniFile.ReadString('PATHS', 'vclpath',
'c:\delphi\source\'));
bpPath := AddBackSlash(IniFile.ReadString('PATHS', 'bppath', 'c:\bp\rtl\'));
ObjectList := IniFile.ReadString('SETTINGS', 'CurrObject', 'delobj.lst');
TextEditor := IniFile.ReadString('SETTINGS', 'TextEditor', 'notepad.exe');
if ObjectList = 'owlobj.lst' then
begin
VCL1.Checked := False;
OWL1.Checked := True;
TurboVision1.Checked := False;
Caption := 'Object Explorer - OWL';
end
else if ObjectList = 'tvobj.lst' then
begin
VCL1.Checked := False;
OWL1.Checked := False;
TurboVision1.Checked := True;
Caption := 'Object Explorer - TV';
end;
GetoePath;
if not (HasIni and FileExists(oePath+ObjectList)) then begin
WelcomeDlg := TWelcomeDlg.Create(Self);
WelcomeDlg.ShowModal;
WelcomeDlg.Free;
NewUser := True;
end;
SList := TStringList.Create;
SList.Sorted := True;
if not NewUser then begin
SList.LoadFromFile(oePath+ObjectList);
for i := 0 to SList.Count - 1 do
ComboBox1.Items.Add(GetClass(SList.Strings[i]));
if ParamCount > 0 then begin
i := SendMessage(ComboBox1.Handle, cb_SelectString, 0, Longint(StrPCopy(cbBuffer, ParamStr(1))));
H := GetDlgItem(ComboBox1.Handle, 1000);
SendM