-
Notifications
You must be signed in to change notification settings - Fork 16
/
DelphiFunctions.pas
1181 lines (1053 loc) · 35.1 KB
/
DelphiFunctions.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{*******************************************************}
{ PHP4Delphi }
{ PHP - Delphi interface }
{ }
{ Author: }
{ Serhiy Perevoznyk }
{ serge_perevoznyk@hotmail.com }
{ http://users.chello.be/ws36637 }
{*******************************************************}
{$I PHP.INC}
{ $Id: DelphiFunctions.pas,v 6.2 02/2006 delphi32 Exp $ }
unit DelphiFunctions;
interface
uses
Windows, SysUtils, Classes,
Controls,
ZendTypes, ZendAPI, PHPTypes, PHPAPI, Dialogs, ShellAPI, typinfo,
{$IFDEF VERSION7}
ActiveX,
ObjComAuto,
{$ENDIF}
Forms, stdctrls;
{$IFDEF VERSION7}
{$METHODINFO ON}
type
TPHPScriptableObject = class(TObjectDispatch)
private
FRetValue : Variant;
FInstanceObj : TObject;
public
function NameToDispID(const AName: string): TDispID;
function Invoke2(dispidMember: TDispID; wFlags: Word;
var pdispparams: TDispParams; Res: PVariant): PVariant;
function GetPropertyByID(ID: TDispID): PVariant;
procedure SetPropertyByID(ID: TDispID; const Prop: array of const);
function CallMethod(ID: TDispID; const Args : array of variant;
NeedResult: Boolean): PVariant;
property InstanceObj : TObject read FInstanceObj write FInstanceObj;
end;
{$METHODINFO OFF}
{$ENDIF}
var
DelphiTable : array [0..12] of zend_function_entry;
object_functions : array[0..2] of zend_function_entry;
author_functions : array[0..2] of zend_function_entry;
DelphiObject : pzend_class_entry;
ce : pzend_class_entry;
{$IFDEF PHP5}
DelphiObjectHandlers : zend_object_handlers;
{$ENDIF}
procedure InitDelphiFunctions;
procedure RegisterInternalClasses(p : pointer);
const
SimpleProps = [tkInteger, tkChar, tkEnumeration, tkFloat,
tkString, tkWChar, tkLString, tkWString, tkVariant];
implementation
//proto string delphi_get_system_directory(void)
{$IFDEF PHP510}
procedure delphi_get_system_directory(ht : integer; return_value : pzval; return_value_ptr : ppzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ELSE}
procedure delphi_get_system_directory(ht : integer; return_value : pzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ENDIF}
var
Dir: array[0..MAX_PATH] of Char;
p : pchar;
begin
GetSystemDirectory(Dir, MAX_PATH);
p := dir;
p := p;
ZVAL_STRING(return_value, p, true);
end;
//proto string delphi_str_date(void)
{$IFDEF PHP510}
procedure delphi_str_date(ht : integer; return_value : pzval; return_value_ptr : ppzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ELSE}
procedure delphi_str_date(ht : integer; return_value : pzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ENDIF}
begin
ZVAL_STRING(return_value, PChar(DateToStr(Date)), true);
end;
//proto float delphi_date(void)
{$IFDEF PHP510}
procedure delphi_date(ht : integer; return_value : pzval; return_value_ptr : ppzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ELSE}
procedure delphi_date(ht : integer; return_value : pzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ENDIF}
begin
ZVAL_DOUBLE(return_value, Date);
end;
//proto string delphi_extract_file_dir(string source)
{$IFDEF PHP510}
procedure delphi_extract_file_dir(ht : integer; return_value : pzval; return_value_ptr : ppzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ELSE}
procedure delphi_extract_file_dir(ht : integer; return_value : pzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ENDIF}
var
Param : pzval_array;
P : PChar;
begin
if ( not (zend_get_parameters_ex(1, Param) = SUCCESS )) then
begin
zend_wrong_param_count(TSRMLS_DC);
Exit;
end;
convert_to_string(param[0]^);
p := PChar(ExtractFileDir(param[0]^.value.str.val));
ZVAL_STRING(return_value, p, true);
dispose_pzval_array(Param);
end;
//proto string delphi_extract_file_drive(string source)
{$IFDEF PHP510}
procedure delphi_extract_file_drive(ht : integer; return_value : pzval; return_value_ptr : ppzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ELSE}
procedure delphi_extract_file_drive(ht : integer; return_value : pzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ENDIF}
var
Param : pzval_array;
P : PChar;
begin
if ( not (zend_get_parameters_ex(1, Param) = SUCCESS )) then
begin
zend_wrong_param_count(TSRMLS_DC);
Exit;
end;
convert_to_string(param[0]^);
p := PChar(ExtractFileDrive(param[0]^.value.str.val));
ZVAL_STRING(return_value, p, true);
dispose_pzval_array(Param);
end;
//proto string delphi_extract_file_name(string source)
{$IFDEF PHP510}
procedure delphi_extract_file_name(ht : integer; return_value : pzval; return_value_ptr : ppzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ELSE}
procedure delphi_extract_file_name(ht : integer; return_value : pzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ENDIF}
var
Param : pzval_array;
P : PChar;
begin
if ( not (zend_get_parameters_ex(1, Param) = SUCCESS )) then
begin
zend_wrong_param_count(TSRMLS_DC);
Exit;
end;
convert_to_string(param[0]^);
p := PChar(ExtractFileName(param[0]^.value.str.val));
ZVAL_STRING(return_value, p, true);
dispose_pzval_array(Param);
end;
//proto string delphi_extract_file_ext(string source)
{$IFDEF PHP510}
procedure delphi_extract_file_ext(ht : integer; return_value : pzval; return_value_ptr : ppzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ELSE}
procedure delphi_extract_file_ext(ht : integer; return_value : pzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ENDIF}
var
Param : pzval_array;
P : PChar;
begin
if ( not (zend_get_parameters_ex(1, Param) = SUCCESS )) then
begin
zend_wrong_param_count(TSRMLS_DC);
Exit;
end;
convert_to_string(param[0]^);
p := PChar(ExtractFileExt(param[0]^.value.str.val));
ZVAL_STRING(return_value, p, true);
dispose_pzval_array(Param);
end;
//proto void delphi_show_message(string message)
{$IFDEF PHP510}
procedure delphi_show_message(ht : integer; return_value : pzval; return_value_ptr : ppzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ELSE}
procedure delphi_show_message(ht : integer; return_value : pzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ENDIF}
var
Param : pzval_array;
P : PChar;
begin
if ( not (zend_get_parameters_ex(1, Param) = SUCCESS )) then
begin
zend_wrong_param_count(TSRMLS_DC);
Exit;
end;
convert_to_string(param[0]^);
p := param[0]^.value.str.val;
ShowMessage(P);
dispose_pzval_array(Param);
end;
//proto string delphi_input_box(string caption, string prompt, string default)
{$IFDEF PHP510}
procedure delphi_input_box(ht : integer; return_value : pzval; return_value_ptr : ppzval;
this_ptr : pzval; return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ELSE}
procedure delphi_input_box(ht : integer; return_value : pzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ENDIF}
var
Param : pzval_array;
Caption, Prompt, Default : string;
P : PChar;
begin
if ( not (zend_get_parameters_ex(3, Param) = SUCCESS )) then
begin
zend_wrong_param_count(TSRMLS_DC);
Exit;
end;
convert_to_string(param[0]^);
convert_to_string(param[1]^);
convert_to_string(param[2]^);
Caption := param[0]^.value.str.val;
Prompt := param[1]^.value.str.val;
Default := param[2]^.value.str.val;
p := PChar(InputBox(Caption, Prompt, Default));
ZVAL_STRING(return_value, PChar(p), true);
dispose_pzval_array(Param);
end;
//proto void delphi_send_message(void)
{$IFDEF PHP510}
procedure delphi_send_email(ht : integer; return_value : pzval; return_value_ptr : ppzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ELSE}
procedure delphi_send_email(ht : integer; return_value : pzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ENDIF}
begin
ShellExecute(0, 'open', 'mailto:serge_perevoznyk@hotmail.com', nil, nil, SW_SHOWNORMAL);
end;
//proto void delphi_visit_homepage(void)
{$IFDEF PHP510}
procedure delphi_visit_homepage(ht : integer; return_value : pzval; return_value_ptr : ppzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ELSE}
procedure delphi_visit_homepage(ht : integer; return_value : pzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ENDIF}
begin
ShellExecute(0, 'open', 'http://users.chello.be/ws36637', nil, nil, SW_SHOW);
end;
//Delphi objects support
{$IFDEF PHP510}
procedure delphi_object_classname(ht : integer; return_value : pzval; return_value_ptr : ppzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ELSE}
procedure delphi_object_classname(ht : integer; return_value : pzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ENDIF}
var
OBJ : TObject;
data: ^ppzval;
P : string;
begin
new(data);
{$IFDEF PHP5}
zend_hash_find(this_ptr^.value.obj.handlers.get_properties(this_ptr, TSRMLS_DC), 'instance', strlen('instance') + 1, data);
{$ELSE}
zend_hash_find(this_ptr^.value.obj.properties, 'instance', strlen('instance') + 1, data);
{$ENDIF}
Obj := TObject(data^^^.value.lval);
P := Obj.ClassName;
ZVAL_STRING(return_value, PChar(p), true);
freemem(data);
end;
{$IFDEF PHP510}
procedure delphi_object_classnameis(ht : integer; return_value : pzval; return_value_ptr : ppzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ELSE}
procedure delphi_object_classnameis(ht : integer; return_value : pzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ENDIF}
var
OBJ : TObject;
data: ^ppzval;
P : PChar;
Param : pzval_array;
begin
if ( not (zend_get_parameters_ex(1, Param) = SUCCESS )) then
begin
zend_wrong_param_count(TSRMLS_DC);
Exit;
end;
convert_to_string(param[0]^);
p := param[0]^.value.str.val;
new(data);
{$IFDEF PHP5}
zend_hash_find(this_ptr^.value.obj.handlers.get_properties(this_ptr, TSRMLS_DC), 'instance', strlen('instance') + 1, data);
{$ELSE}
zend_hash_find(this_ptr^.value.obj.properties, 'instance', strlen('instance') + 1, data);
{$ENDIF}
Obj := TObject(data^^^.value.lval);
ZVAL_BOOL(return_value,Obj.ClassNameIs(p));
freemem(data);
end;
{$IFDEF PHP4}
function delphi_set_property_handler(property_reference : Pzend_property_reference; value : pzval) : integer; cdecl;
var
this_ptr : pzval;
OBJ : TObject;
data: ^ppzval;
element : pzend_list_element;
prop : pzend_overloaded_element;
p : pointer;
propname : string;
pt : TTypeKind;
begin
element := property_reference^.elements_list^.head;
p := @element^.data;
prop := pzend_overloaded_element(p);
propname := prop^.element.value.str.val;
this_ptr := property_reference^._object;
new(data);
zend_hash_find(this_ptr^.value.obj.properties, 'instance', strlen('instance') + 1, data);
Obj := TObject(data^^^.value.lval);
freemem(data);
pt := PropType(Obj, propname);
if ( pt in SimpleProps) then
SetPropValue(OBJ, propname, zval2variant(value^))
else
if pt = tkClass then
begin
Obj := GetObjectProp(Obj, propname);
while element <> nil do
begin
element := element^.prev;
p := @element^.data;
prop := pzend_overloaded_element(p);
propname := prop^.element.value.str.val;
pt := PropType(Obj, propname);
if ( pt in SimpleProps) then
begin
SetPropValue(OBJ, propname, zval2variant(value^));
break;
end
else
if pt = tkClass then
Obj := GetObjectProp(Obj, propname);
end;
end;
Result := SUCCESS;
end;
procedure delphi_get_property_handler(val : pzval; property_reference : PZend_property_reference); cdecl;
var
this_ptr : pzval;
OBJ : TObject;
data: ^ppzval;
element : pzend_list_element;
prop : pzend_overloaded_element;
p : pointer;
propname : string;
pt : TTypeKind;
begin
element := property_reference^.elements_list^.head;
p := @element^.data;
prop := pzend_overloaded_element(p);
propname := prop^.element.value.str.val;
this_ptr := property_reference^._object;
new(data);
zend_hash_find(this_ptr^.value.obj.properties, 'instance', strlen('instance') + 1, data);
Obj := TObject(data^^^.value.lval);
freemem(data);
pt := PropType(Obj, propname);
if ( pt in SimpleProps) then
variant2zval(GetPropValue(OBJ, propname), val)
else
if pt = tkClass then
begin
Obj := GetObjectProp(Obj, propname);
while element <> nil do
begin
element := element^.prev;
p := @element^.data;
prop := pzend_overloaded_element(p);
propname := prop^.element.value.str.val;
pt := PropType(Obj, propname);
if ( pt in SimpleProps) then
begin
variant2zval(GetPropValue(OBJ, propname), val);
break;
end
else
if pt = tkClass then
Obj := GetObjectProp(Obj, propname);
end;
end;
end;
procedure _delphi_get_property_wrapper; assembler;
asm
push ebp
mov ebp,esp
sub esp,50h
push ebx
push esi
push edi
lea edi,[ebp-50h]
mov ecx,14h
mov eax,0CCCCCCCCh
rep stosd
mov eax,dword ptr [ebp+0Ch]
push eax
lea ecx,[ebp-10h]
push ecx
call delphi_get_property_handler
add esp,8
mov edx,dword ptr [ebp+8]
mov eax,dword ptr [ebp-10h]
mov dword ptr [edx],eax
mov ecx,dword ptr [ebp-0Ch]
mov dword ptr [edx+4],ecx
mov eax,dword ptr [ebp-8]
mov dword ptr [edx+8],eax
mov ecx,dword ptr [ebp-4]
mov dword ptr [edx+0Ch],ecx
mov eax,dword ptr [ebp+8]
pop edi
pop esi
pop ebx
add esp,50h
cmp ebp,esp
mov esp,ebp
pop ebp
ret
end;
procedure delphi_call_function(ht : integer; return_value : pzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer; property_reference : Pzend_property_reference ); cdecl;
var
OBJ : TObject;
data: ^ppzval;
element : pzend_list_element;
prop : pzend_overloaded_element;
p : pointer;
MethodName : string;
Params : pzval_array;
M, D : integer;
begin
element := property_reference^.elements_list^.head;
p := @element^.data;
prop := pzend_overloaded_element(p);
MethodName := prop^.element.value.str.val;
this_ptr := property_reference^._object;
new(data);
zend_hash_find(this_ptr^.value.obj.properties, 'instance', strlen('instance') + 1, data);
Obj := TObject(data^^^.value.lval);
freemem(data);
if ( Obj.InheritsFrom(TCustomEdit) ) then
begin
if SameText(MethodName, 'Clear') then
TCustomEdit(Obj).Clear;
if SameText(MethodName, 'ClearSelection') then
TCustomEdit(Obj).ClearSelection;
if SameText(MethodName, 'CopyToClipboard') then
TCustomEdit(Obj).CopyToClipboard;
if SameText(MethodName, 'ControlCount') then
ZVAL_LONG(return_value, TCustomEdit(Obj).ControlCount);
if SameText(MethodName, 'ScaleBy') then
begin
if ht > 0 then
begin
if ( not (zend_get_parameters_ex(ht, Params) = SUCCESS )) then
begin
zend_wrong_param_count(TSRMLS_DC);
Exit;
end;
end;
M := Params[0]^.value.lval;
D := Params[1]^.value.lval;
TCustomEdit(Obj).ScaleBy(M, D);
dispose_pzval_array(Params);
end;
end;
end;
{$ENDIF}
{$IFDEF PHP5}
// Read object property value (getter)
function delphi_get_property_handler(_object : pzval; member : pzval; _type : integer; TSRMLS_DC : pointer) : pzval; cdecl;
var
retval : pzval;
OBJ : TObject;
data: ^ppzval;
propname : string;
object_properties : PHashTable;
{$IFDEF VERSION7}
Scripter : TPHPScriptableObject;
V : Variant;
{$ELSE}
pt : TTypeKind;
_property : PChar;
{$ENDIF}
begin
retval := emalloc(sizeof(zval));
FillChar(retval^, sizeof(zval), 0);
propname := member^.value.str.val;
new(data);
try
object_properties := Z_OBJPROP(_object^);
if zend_hash_find(object_properties, 'instance', strlen('instance') + 1, data) = SUCCESS then
Obj := TObject(data^^^.value.lval)
else
Obj := nil;
finally
freemem(data);
end;
if Assigned(Obj) then
begin
{$IFDEF VERSION7}
Scripter := TPHPScriptableObject(Obj);
V := Scripter.GetPropertyByID(Scripter.NameToDispID(propName))^;
variant2zval(V, retval);
{$ELSE}
pt := PropType(Obj, propname);
if ( pt in SimpleProps) then
variant2zval(GetPropValue(OBJ, propname), retval)
else
if pt = tkClass then
begin
Obj := GetObjectProp(Obj, propname);
retval._type := IS_OBJECT;
object_init(retval, DelphiObject, TSRMLS_DC);
_property := 'instance';
add_property_long_ex(retval, _property, strlen(_property) + 1, Integer(Obj), TSRMLS_DC);
retval.value.obj.handlers := @DelphiObjectHandlers;
end;
{$ENDIF}
end;
Result := retval;
end;
// Write object property value (setter)
procedure delphi_set_property_handler(_object : pzval; member : pzval; value : pzval; TSRMLS_DC : pointer); cdecl;
var
OBJ : TObject;
data: ^ppzval;
propname : string;
object_properties : PHashTable;
{$IFDEF VERSION7}
Scripter : TPHPScriptableObject;
{$ELSE}
pt : TypInfo.TTypeKind;
{$ENDIF}
begin
propname := member^.value.str.val;
new(data);
try
object_properties := Z_OBJPROP(_object^);
if zend_hash_find(object_properties, 'instance', strlen('instance') + 1, data) = SUCCESS then
Obj := TObject(data^^^.value.lval)
else
Obj := nil;
finally
freemem(data);
end;
if Assigned(Obj) then
begin
{$IFDEF VERSION7}
Scripter := TPHPScriptableObject(Obj);
if SameText('Parent', propname) then
begin
TWinControl(Scripter.InstanceObj).Parent := TWinControl(value^.value.lval);
end
else
Scripter.SetPropertyByID(Scripter.NameToDispID(propname), [zval2variant(value^)] );
{$ELSE}
pt := TypInfo.PropType(Obj, propname);
if ( pt in SimpleProps) then
SetPropValue(OBJ, propname, zval2variant(value^))
{$ENDIF}
end;
end;
{$IFDEF PHP510}
function delphi_call_method(method : pchar; ht : integer; return_value : pzval; return_value_ptr : ppzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer) : integer; cdecl;
{$ELSE}
function delphi_call_method(method : pchar; ht : integer; return_value : pzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer) : integer; cdecl;
{$ENDIF}
{$IFDEF VERSION7}
var
OBJ : TObject;
data: ^ppzval;
Params : pzval_array;
Scripter : TPHPScriptableObject;
ValArray : array of Variant;
I : integer;
V : variant;
{$ENDIF}
begin
{$IFDEF VERSION7}
new(data);
if zend_hash_find(this_ptr^.value.obj.handlers.get_properties(this_ptr, TSRMLS_DC), 'instance', strlen('instance') + 1, data) = SUCCESS then
Obj := TObject(data^^^.value.lval)
else
Obj := nil;
freemem(data);
if Obj <> nil then
begin
Scripter := TPHPScriptableObject(Obj);
if ht > 0 then
begin
if ( not (zend_get_parameters_ex(ht, Params) = SUCCESS )) then
begin
zend_wrong_param_count(TSRMLS_DC);
Result := FAILURE;
Exit;
end;
end;
SetLength(ValArray, ht);
for I := 0 to ht - 1 do
ValArray[i] := zval2variant(Params[i]^^);
V := Scripter.CallMethod(Scripter.NameToDispID(method), ValArray, true)^;
variant2zval(V, return_value);
dispose_pzval_array(Params);
end;
{$ENDIF}
result := SUCCESS;
end;
function delphi_get_method(_object : pzval; method_name : pchar; method_len : integer; TSRMLS_DC : pointer) : PzendFunction; cdecl;
var
fnc : pZendFunction;
begin
fnc := emalloc(sizeof(TZendFunction));
FillChar(fnc^, sizeOf(TZendFunction), 0);
fnc^.internal_function._type := ZEND_OVERLOADED_FUNCTION;
fnc^.internal_function.function_name := estrndup(method_name, method_len);
fnc^.internal_function.handler := @delphi_call_method;
result := fnc;
end;
{$ENDIF}
{$IFDEF PHP510}
procedure delphi_get_author(ht : integer; return_value : pzval; return_value_ptr : ppzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ELSE}
procedure delphi_get_author(ht : integer; return_value : pzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ENDIF}
var
properties : array[0..3] of pchar;
begin
properties[0] := 'name';
properties[1] := 'last';
properties[2] := 'height';
properties[3] := 'email';
{$IFDEF PHP4}
_object_init_ex(return_value, ce, nil, 0, TSRMLS_DC );
{$ELSE}
object_init(return_value, ce, TSRMLS_DC );
{$ENDIF}
{$IFDEF PHP4}
add_property_string_ex(return_value, properties[0], strlen(properties[0]) + 1, 'Serhiy', 1);
add_property_string_ex(return_value, properties[1], strlen(properties[1]) + 1, 'Perevoznyk', 1);
{$ELSE}
add_property_string_ex(return_value, properties[0], strlen(properties[0]) + 1, 'Serhiy', 1, TSRMLS_DC);
add_property_string_ex(return_value, properties[1], strlen(properties[1]) + 1, 'Perevoznyk', 1, TSRMLS_DC);
{$ENDIF}
{$IFDEF PHP5}
add_property_long_ex(return_value, properties[2], strlen(properties[2]) + 1, 185, TSRMLS_DC);
{$ELSE}
add_property_long_ex(return_value, properties[2], strlen(properties[2]) + 1, 185);
{$ENDIF}
{$IFDEF PHP4}
add_property_string_ex(return_value, properties[3], strlen(properties[3]) + 1, 'serge_perevoznyk@hotmail.com', 1);
{$ELSE}
add_property_string_ex(return_value, properties[3], strlen(properties[3]) + 1, 'serge_perevoznyk@hotmail.com', 1, TSRMLS_DC);
{$ENDIF}
end;
{$IFDEF PHP510}
procedure register_delphi_object(ht : integer; return_value : pzval; return_value_ptr : ppzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ELSE}
procedure register_delphi_object(ht : integer; return_value : pzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ENDIF}
var
_property : pchar;
Param : pzval_array;
Obj : TObject;
{$IFDEF VERSION7}
Scripter : TPHPScriptableObject;
{$ENDIF}
begin
if ( not (zend_get_parameters_ex(1, Param) = SUCCESS )) then
begin
zend_wrong_param_count(TSRMLS_DC);
Exit;
end;
Obj := TObject(Param[0]^.value.lval);
{$IFDEF VERSION7}
Scripter := TPHPScriptableObject.Create(Obj, false);
Scripter.InstanceObj := Obj;
Obj := Scripter;
{$ENDIF}
_property := 'instance';
return_value._type := IS_OBJECT;
{$IFDEF PHP4}
_object_init_ex(return_value, DelphiObject, nil, 0, TSRMLS_DC );
{$ELSE}
object_init(return_value, DelphiObject, TSRMLS_DC);
{$ENDIF}
{$IFDEF PHP5}
add_property_long_ex(return_value, _property, strlen(_property) + 1, Integer(Obj), TSRMLS_DC);
{$ELSE}
add_property_long_ex(return_value, _property, strlen(_property) + 1, Integer(Obj));
{$ENDIF}
{$IFDEF PHP5}
return_value.value.obj.handlers := @DelphiObjectHandlers;
{$ENDIF}
dispose_pzval_array(Param);
end;
{$IFDEF PHP510}
procedure register_delphi_component(ht : integer; return_value : pzval; return_value_ptr : ppzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ELSE}
procedure register_delphi_component(ht : integer; return_value : pzval; this_ptr : pzval;
return_value_used : integer; TSRMLS_DC : pointer); cdecl;
{$ENDIF}
var
_property : pchar;
Param : pzval_array;
Obj : TObject;
ObjName : string;
php : TComponent;
gl : psapi_globals_struct;
p : pointer;
Form : TCustomForm;
{$IFDEF VERSION7}
Scripter : TPHPScriptableObject;
{$ENDIF}
begin
if ( not (zend_get_parameters_ex(1, Param) = SUCCESS )) then
begin
zend_wrong_param_count(TSRMLS_DC);
Exit;
end;
ObjName := Param[0]^.value.str.val;
p := ts_resource_ex(0, nil);
gl := GetSAPIGlobals(p);
php := TComponent(gl^.server_context);
if not Assigned(php) then
begin
ZVAL_NULL(return_value);
exit;
end;
Form := TCustomForm(php.Owner);
if not Assigned(Form) then
begin
ZVAL_NULL(return_value);
exit;
end;
if SameText(Form.Name, ObjName) then
Obj := Form
else
OBJ := Form.FindComponent(ObjName);
if not Assigned(Obj) then
begin
ZVAL_NULL(return_value);
exit;
end;
{$IFDEF VERSION7}
Scripter := TPHPScriptableObject.Create(Obj, false);
Obj := Scripter;
{$ENDIF}
_property := 'instance';
{$IFDEF PHP4}
_object_init_ex(return_value, DelphiObject, nil, 0, TSRMLS_DC );
{$ELSE}
object_init(return_value, DelphiObject, TSRMLS_DC);
{$ENDIF}
{$IFDEF PHP5}
add_property_long_ex(return_value, _property, strlen(_property) + 1, Integer(Obj), TSRMLS_DC);
{$ELSE}
add_property_long_ex(return_value, _property, strlen(_property) + 1, Integer(Obj));
{$ENDIF}
{$IFDEF PHP5}
return_value.value.obj.handlers := @DelphiObjectHandlers;
{$ENDIF}
dispose_pzval_array(Param);
end;
procedure InitDelphiFunctions;
begin
PHP_FUNCTION(DelphiTable[0], 'delphi_date', @delphi_date);
PHP_FUNCTION(DelphiTable[1], 'delphi_extract_file_dir', @delphi_extract_file_dir);
PHP_FUNCTION(DelphiTable[2], 'delphi_extract_file_drive', @delphi_extract_file_drive);
PHP_FUNCTION(DelphiTable[3], 'delphi_extract_file_name', @delphi_extract_file_name);
DelphiTable[4].fname := 'delphi_extract_file_ext';
DelphiTable[4].handler := @delphi_extract_file_ext;
{$IFDEF PHP4}
DelphiTable[4].func_arg_types := nil;
{$ELSE}
DelphiTable[4].arg_info := nil;
{$ENDIF}
DelphiTable[5].fname := 'delphi_show_message';
DelphiTable[5].handler := @delphi_show_message;
{$IFDEF PHP4}
DelphiTable[5].func_arg_types := nil;
{$ELSE}
DelphiTable[5].arg_info := nil;
{$ENDIF}
DelphiTable[6].fname := 'register_delphi_object';
delphitable[6].handler := @register_delphi_object;
{$IFDEF PHP4}
DelphiTable[6].func_arg_types := nil;
{$ELSE}
DelphiTable[6].arg_info := nil;
{$ENDIF}
DelphiTable[7].fname := 'delphi_get_author';
DelphiTable[7].handler := @delphi_get_author;
{$IFDEF PHP4}
DelphiTable[7].func_arg_types := nil;
{$ELSE}
DelphiTable[7].arg_info := nil;
{$ENDIF}
DelphiTable[8].fname := 'delphi_str_date';
DelphiTable[8].handler := @delphi_str_date;
{$IFDEF PHP4}
DelphiTable[8].func_arg_types := nil;
{$ELSE}
DelphiTable[8].arg_info := nil;
{$ENDIF}
PHP_FUNCTION(DelphiTable[9], 'delphi_get_system_directory', @delphi_get_system_directory);
PHP_FUNCTION(DelphiTable[10], 'delphi_input_box', @delphi_input_box);
PHP_FUNCTION(DelphiTable[11], 'register_delphi_component', @register_delphi_component);
DelphiTable[12].fname := nil;
DelphiTable[12].handler := nil;
end;
procedure RegisterInternalClasses(p : pointer);
var
author_class_entry : Tzend_class_entry;
delphi_object_entry : TZend_class_entry;
begin
object_functions[0].fname := 'delphi_classname';
object_functions[0].handler := @delphi_object_classname;
object_functions[1].fname := 'delphi_classnameis';
object_functions[1].handler := @delphi_object_classnameis;
INIT_CLASS_ENTRY(delphi_object_entry, 'delphi_class' , @object_functions);
{$IFDEF PHP4}
Delphi_Object_Entry.handle_property_get := @_delphi_get_property_wrapper;
Delphi_Object_Entry.handle_property_set := @delphi_set_property_handler;
Delphi_Object_Entry.handle_function_call := @delphi_call_function;
{$ELSE}
Move(zend_get_std_object_handlers()^, DelphiObjectHandlers, sizeof(zend_object_handlers));
DelphiObjectHandlers.read_property := @delphi_get_property_handler;
DelphiObjecthandlers.write_property := @delphi_set_property_handler;
DelphiObjectHandlers.call_method := @delphi_call_method;
DelphiObjectHandlers.get_method := @delphi_get_method;
{$ENDIF}
DelphiObject := zend_register_internal_class(@delphi_object_entry, p);
author_functions[0].fname := 'send_email';
author_functions[0].handler := @delphi_send_email;
author_functions[1].fname := 'visit_homepage';
author_functions[1].handler := @delphi_visit_homepage;
INIT_CLASS_ENTRY(author_class_entry, 'php4delphi_author', @author_functions);
ce := zend_register_internal_class(@author_class_entry, p);
end;
{$IFDEF VERSION7}
{
Delphi scripting support
The Original Code is: JvOle2Auto.PAS, released on 2002-07-04.
The Initial Developers of the Original Code are: Fedor Koshevnikov, Igor Pavluk and Serge Korolev
Copyright (c) 1997, 1998 Fedor Koshevnikov, Igor Pavluk and Serge Korolev
Copyright (c) 2001,2002 SGB Software
All Rights Reserved.
}
function TPHPScriptableObject.NameToDispID(const AName: string): TDispID;
var
CharBuf: array [0..255] of WideChar;
P: array [0..0] of PWideChar;
begin
StringToWideChar(AName, @CharBuf[0], 256);
P[0] := @CharBuf[0];
GetIDsOfNames(GUID_NULL, @P, 1, GetThreadLocale, @Result);
end;