Skip to content

Commit 311464b

Browse files
committed
fix Delphi sample
1 parent 37db321 commit 311464b

3 files changed

Lines changed: 11 additions & 14 deletions

File tree

Delphi/Get data/Unit1.dcu

12.2 KB
Binary file not shown.

Delphi/Get data/Unit1.dfm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ object Main: TMain
1414
Font.Style = []
1515
OldCreateOrder = False
1616
Position = poScreenCenter
17-
OnClose = FormClose
1817
OnCreate = FormCreate
1918
PixelsPerInch = 96
2019
TextHeight = 13

Delphi/Get data/Unit1.pas

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ TMain = class(TForm)
5454
procedure FormCreate(Sender: TObject);
5555
procedure Button1Click(Sender: TObject);
5656
procedure Button2Click(Sender: TObject);
57-
procedure FormClose(Sender: TObject; var Action: TCloseAction);
5857
private
5958
{ Private declarations }
6059
public
@@ -99,7 +98,7 @@ _Controller = record
9998

10099
var
101100
Main: TMain;
102-
DriverPath: string;
101+
LibPath: string;
103102
DllHandle: HMODULE;
104103
GetHMDData: function(out myHMD: THMD): DWORD; stdcall;
105104
GetControllersData: function(out myController, myController2: TController): DWORD; stdcall;
@@ -110,15 +109,16 @@ implementation
110109

111110
{$R *.dfm}
112111

113-
procedure GetDriverPath;
112+
procedure GetLibPath;
114113
var
115114
Reg: TRegistry;
116115
begin
116+
LibPath:='';
117117
Reg:=TRegistry.Create;
118118
Reg.RootKey:=HKEY_CURRENT_USER;
119119
if Reg.OpenKey('\Software\TrueOpenVR', false) = false then Exit;
120-
if FileExists(Reg.ReadString('Drivers') + Reg.ReadString('Driver')) = false then Exit;
121-
DriverPath:=Reg.ReadString('Drivers') + Reg.ReadString('Driver');
120+
LibPath:=Reg.ReadString('Library');
121+
if FileExists(LibPath) = false then LibPath:='';
122122
Reg.CloseKey;
123123
Reg.Free;
124124
end;
@@ -214,6 +214,8 @@ procedure TMain.GetBtnClick(Sender: TObject);
214214

215215
procedure TMain.CloseBtnClick(Sender: TObject);
216216
begin
217+
if DllHandle <> 0 then
218+
FreeLibrary(DllHandle);
217219
Close;
218220
end;
219221

@@ -222,9 +224,9 @@ procedure TMain.FormCreate(Sender: TObject);
222224
Label32.Caption:='TOVR - Open Source Virtual Reality' + #13#10 + 'standard for all devices';
223225
Application.Title:=Caption;
224226

225-
GetDriverPath;
226-
if FileExists(DriverPath) then begin
227-
DllHandle:=LoadLibrary(PChar(DriverPath));
227+
GetLibPath;
228+
if LibPath <> '' then begin
229+
DllHandle:=LoadLibrary(PChar(LibPath));
228230
@GetHMDData:=GetProcAddress(DllHandle, 'GetHMDData');
229231
@GetControllersData:=GetProcAddress(DllHandle, 'GetControllersData');
230232
@SetControllerData:=GetProcAddress(DllHandle, 'SetControllerData');
@@ -240,6 +242,7 @@ procedure TMain.Button1Click(Sender: TObject);
240242
iResult: integer;
241243
begin
242244
iResult:=SetCentering(IDHMD);
245+
if iResult = 1 then ShowMessage('Centering success');
243246
end;
244247

245248
procedure TMain.Button2Click(Sender: TObject);
@@ -248,9 +251,4 @@ procedure TMain.Button2Click(Sender: TObject);
248251
SetControllerData(IDController2, 42517);
249252
end;
250253

251-
procedure TMain.FormClose(Sender: TObject; var Action: TCloseAction);
252-
begin
253-
FreeLibrary(DllHandle);
254-
end;
255-
256254
end.

0 commit comments

Comments
 (0)