COMDCOM objects pass array through Variant

zhaozj2021-02-11  204

Because the COM / DCOM object is not running in the client program (except for the COM object, even if so, in order to unify the interface, the inner process COM must not pass the pointer), and all the programs in Win32 have their own independent 2GB The memory space, the program and the program transmits pointer (memory address) are meaningless, and a large number of data such as arrays, strings is allocated in the program, and then use the pointer to add internal deployment. If you access data, how do you pass in the COM / DCOM object? A new variable Variant is introduced in Win32, and an array can be passed through Variant. Specific implementation method, Delphi is implemented as:

Server (COM / DCOM program): procedure ttestdcom.send4 (size: integer; d1: olevariant); type tdata = array [0..999] of byte; var data: tdata; i: integer; begin for i: = 0 to Size-1 Do Begin Data [I]: = D1 [I]; END;

CLEINT:

Var D1: Olevariant; Begin D1: = VararrayCreate ([0,99], Varbyte;

{D1 [1]: = 45; .... file: // Deposit value into D1

} S.send4 (99, d1); file: // s is the TestDcom object end;

Author: Gao Su-mei

Simple method for configuring data engines (BDE, SQL LINK)

When the database program is distributed, you need to carry the data engine (BDE, SQL LINK), and configure the data engine after the client is installed, such as username, password (password), and more. If you are manually configured, the workload is relatively large. At this time, we can use InstallShield for Delphi to easily implement configuration. When making an installer with InstallShield for Delphi, there is a * .iwz text file in the directory where the installer is generated, as long as it is manually added in the [Idapi Alias] clip. E.g:

[IDAPI Alias]

Username = sysdba

Password = MasterKey

The data engine is automatically configured after the installer.

Method for making fast button bars

Each graphic button on the fast button bar represents a common function, while these graphic buttons are more common than ordinary icons, they can place larger, more image graphics, can even bring short tips, which User's most commonly used features is very helpful. Based on the above reasons, more and more Windows applications use a fast button strip to improve the interface interface. When the author is programmed with Delphi, two different methods are used to implement the fast button bar. This article combines an instance of the fast button bar with two groups, a total of six buttons, listing the specific design steps of these two methods. .

Group generation method

(1) Place a panel1 object on the form, as a carrier of the graphic button.

(2) Set the attribute attribute of Panel1, which is empty, attribute Align is Altop, adjust its height to the appropriate size.

(3) Place six SpeedButton buttons on Panel1 (select SpeedButton because it has floating characteristics).

(4) Place two Bevel objects on Panel1, adjust its location and size, and used to separate the button group. (5) Adjust the size of SpeedButton1 and the position in Panel1.

(6) Select SpeedButton1 to set its property FLAT to TRUE.

(7) Click the omitted number of the miniPH corresponding to the attribute glyph of SpeedButton1, open the PictureEeditor window, select a symbolizing icon. Setting attribute showhint to true, property hint is "query".

(8) The properties of the remaining SPEEDBUTTON buttons are set separately according to the methods of steps (5) to (7).

In this way, a quick button bar is completed. When running, the quick button is displayed in a floating mode. When the mouse is moved to it, the display button is displayed, and a small prompt is displayed.

2. Borrow Toolbar generation method

(1) Place a TOOLBAR1 object on the form.

(2) Set the properties of Toolbar1 EDGEBORDERS.EBLEFT, EBTOP, EBRIGHT, EBBUTTOM all; attribute Flat is true; adjust the size of Toolbar1 to the appropriate size.

(3) Select Toolbar1, use the right-click quick order, and click NewButton and NewseParator to add six button Toolbutton and two separate column lines.

(4) Any option to select a Toolbutton button to adjust its size to a suitable size, all ToolButton is also adjusted at the same time.

(5) Set the properties of Toolbar1 BorderWidth to 3 to adjust the location of Toolbutton.

(6) Place an ImageList1 object on the form, set its properties height, and width, to accommodate larger images.

(7) Double-click ImageList1, and load six images via the "Add", and correspond to the six Toolbutton in Toolbar1.

(8) Set the properties of Toolbar1 images to imagelist1.

(9) Set six ToolButton's properties showHint to true and set the respective small prompt properties Hint.

(10) You can also set the picture set when Toolbar1's HotImages specifies the image point when the mouse pointing to the button.

The quick button bar implemented by Toolbar is similar to the first method.

The above two methods can achieve the quick button bar, but each has a thousand autumn: the first design process is simpler; the second method provides more features, such as using hotimages to specify the image set when the mouse pointing to the button. The reader may wish to choose one and continue to improve its function.

Establish a temporary table

Data input is an inevitable link to the development of the database program. In the Client / Server structure, the client may be submitted to the server's background database, which requires the local (client) to establish a temporary data table to store data input data, after submit, clear Local data sheet. The advantage of this method is to improve input efficiency and reduce network burden.

Since the data amount of the user is in a general case (no more than hundreds of records), the temporary table can be built in memory so that the processing speed is faster. Temporary table creation has the following two methods:

1. Create a temporary table using the query control

Step 1: Place the query control (TQuery) on the form and set the connected data sheet.

Step 2: Add the following statement:

TQuery. Cachedupdates = true;

TQuery. RequestLive = true.

Step 3: Add a WHERE child statement after the original SQL statement, requiring the result of the SQL query after adding this WHERE child statement.

For example: SELECT BIOLIFE. "Species no", Category, Common_Name, Biolife. "Species Name", Biolife. "Length (cm)", Length_IN, Notes, Graphic

From "biolife.db" Biolife

Where biolife.category = 'a' and biolife.category = 'b'

This temporary table is established.

2. Create a temporary table using the code

The function code is as follows:

Function CreateTableInMemory (const Afielddefs: tfielddefs):

TDataSet;

Var Temptable: TclientDataSet;

Begin

Temptable: = NIL;

Result: = NIL;

IF Afielddefs <> nil dam

Begin

Try

Temptable: = TclientDataSet.create (Application);

Temptable.fielddefs.assign (AfieldDefs);

Temptable.created;

Result: = (Temptable as TdataSet);

Except

IF Temptable <> nil damptable.free;

Result: = NIL;

Raise;

end

end

END;

Call as follows:

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);

Var adataset: tdatanet;

Begin

Adataset: = TDataSet.create (Self);

With adataset.fielddefs do

Begin

Add ('Name', FTString, 30, False);

Add ('Value', Ftinteger, 0, False);

END;

With datasource1 do

Begin

DataSet: = CreateTableInMemory; Adataset.fieldDefs;

DataSet.open;

END;

Adataset.free;

END;

In this way, the temporary table is created.

Method 1 is simple, but since the query control is used to empty the data, you need to query the server backbench database, so the speed is slightly slow, and it is not applicable to the field of several data tables in the temporary table. Method 2 has a wide range of applications, fast, but needs to write code.

Use functions in the InterBase database

When the programmer may use InterBase as a background database, it is often used to provide an inconvenience for the function provided (only four), and the complex stored procedure cannot be easily written. Interbase itself cannot write a function, but it can use an external function (call the function in the DLL). The following example shows how to declare the substr function in InterBase.

Declare External Function Substr

CString (80), Smallint, Smallint

Returns cstring (80)

Entry_point "ib_udf_substr" module_name "ib_udf"

Where: Module_name is the name of the DLL, entry_point is the function name.

You can use it after the declaration, for example:

SELECT SUBSTR (Country)

From country

This example uses the IBLOCAL database that comes with Delphi installation. Users can write functions to expand Interbase to implement remote screens with Delphi to capture Shandong Juli Co., Ltd. CAD Center Tan Recreation - in network management, sometimes need By monitoring the remote computer screen to understand the usage of the online microcomputer. Although there are many software on the market to implement this feature, some can even perform remote control, but lack flexibility in use, if you cannot specify the size and position of the remote computer screen area, thereby can't monitor multiple screens simultaneously on one screen. . In fact, it is possible to prepare a flexible remote screen crawler tool with Delphi.

---- First, hardware and software requirements.

---- Windows95 / 98 peer-to-peer network, computer (hereinafter referred to as the master) and the monitored computer (hereinafter referred to as controlled machine) must have a TCP / IP protocol and configure it correctly. If there is no network, you can debug on a single computer.

---- Second, implementation method.

---- Develop two applications, one for vclient.exe, mounted on a controlled machine, the other is VSERVER.EXE, mounted on the master. VServer.exe Specifies the IP address of the controlled machine to be monitored and the size and location of the area to be captured on the controlled machine screen, and issue the screen capture instruction to vclient.exe, Vclient.exe gets the instruction, in controlled The specified area is selected on the screen, generate a data stream, send it back to the master, and display the BMP image of the capture area on the main control. As can be seen from the above process, the key to the method is two: one, how is the screen capture on a controlled machine, and the second is how to transfer data in two computers through the TCP / IP protocol.

---- UDP (User DataGram Protocol) is one of the widely used communication protocols on the Internet. Unlike TCP protocols, it is a non-connected transport protocol, no confirmation mechanism, reliability is not as good as TCP, but its efficiency is higher than TCP, which is used for remote screen monitoring or more suitable. At the same time, the UDP control does not distinguish between server-side and clients, only distinguishes transmitting ends and receiving ends, which is more simple, so select UDP protocol, use the TNMUDP control provided by Delphi 4.0.

---- Third, create a demo.

---- First step, prepare vclient.exe files. New Delphi project, set the Name property of the default form to "Client". Add TNMUDP control, the Name property is set to "CUDP"; set to "1111", allow the control CUDP to monitor the 1111 port of the controlled machine, when the data is sent to the port, the control CUDP's OnDataReceiveD event; RemotePort property To "2222", when the control CUDP sends data, the data is sent to 2222 ports of the master.

---- Add variable definitions after IMPLEMentation

Const buffsize = 2048; {Buffer size of each data} var bmpstream: tmemorystream; Leftsize: longint; {Send every byte after each data}

Add code to Client's oncreate event: procedure tclient.formcreate (sender: Tobject); begin bmpstream: = tmemorystream.create;

Add code to the Client OnDestroy event: procedure TClient.FormDestroy (Sender: TObject); begin BmpStream.Free; end; add code to the control CUDP OnDataReceived event of: procedure TClient.CUDPDataReceived (Sender: TComponent; NumberBytes: Integer; FromIP: String VAR CTRLCODE: ARRAY [0..29] of char; buf: array [0..bufsize-1] of char; TMPSTR: STRING; Sendsize, Leftpos, Toppos, Rightpos, Bottompos: Integer; Begin Cudp.Readbuffer Ctrlcode, NumberBytes; {Read Control Code} if Ctrlcode [0] Ctrlcode [1] Ctrlcode [2] Ctrlcode [3] = 'show' The begin {The first 4 digits of the control code are "show" indicate the master The machine issued a gripper command} if bmpstream.size = 0 THEN {No data can be sent, the screen is required to generate data} begintmpstr: = strPas (ctrlcode); tmpstr: = COPY (Tmpstr, 5, Length (tmpstr) -4; Leftpos: = StrtOINT (Copy (Tmpstr, 1, POS (':', tmpstr) -1); TMPSTR: = Copy (Tmpstr, POS (':', tmpstr) 1, Length (tmpstr) -pos (' : ', Tmpstr); TOPPOS: = STRTOINT (COPY (TmpStr, 1, POS (': ', tmpstr) -1)); TMPSTR: = Copy (Tmpstr, POS (': ', tmpstr) 1, Length (TMPSTR) -POS (':', tmpstr)); Rightpos: = STRTOINT (COPY (Tmpstr, 1, POS (':', tmpstr) -1)); bottompos: = start (Copy (tmpstr, POS : ', Tmpstr) 1, Length (Tmpstr) -pos (': ' , TmpStr))); ScreenCap (LeftPos, TopPos, RightPos, BottomPos); {screen capture} end; if LeftSize> BufSize then SendSize: = BufSizeelse SendSize: = LeftSize; BmpStream.ReadBuffer (Buf, SendSize); LeftSize: = LeftSize -Sendsize; if leftsize = 0 dam, {empty flow} cudp.remotehost: = fromip; {fromip is the main controller IP address} cudp.sendbuffer (buf, sendsize); {Send data to the master 2222 port} End;

Wherein ScreenCap custom function, interception of the screen designated area code is as follows: procedure TClient.ScreenCap (LeftPos, TopPos, RightPos, BottomPos: integer); var RectWidth, RectHeight: integer; SourceDC, DestDC, Bhandle: integer; Bitmap: TBitmap; begin RectWidth: = RightPos-LeftPos; RectHeight: = BottomPos-TopPos; SourceDC: = CreateDC ( 'DISPLAY', '', '', nil); DestDC: = CreateCompatibleDC (SourceDC); Bhandle: = CreateCompatibleBitmap (SourceDC, RectWidth, RectHeight); SelectObject (DestDC, Bhandle); BitBlt (DestDC, 0,0, RectWidth, RectHeight, SourceDC, LeftPos, TopPos, SRCCOPY); Bitmap: = TBitmap.Create; Bitmap.Handle: = BHandle; BitMap.SaveToStream (BmpStream ); Bmpstream.position: = 0; Leftsize: = bmpstream.size; bitmap.free; deletedc (DESTDC); ReleaseDC (Bhandle, SourceDC); END; exists "c: /vclient/clnunit.pas" and "C: /VCLIENT/VCLIENT.DPR "and compiled. ---- Step 2, prepare the vServer.exe file. Create a new Delphi project, set the Name property of the form to "Server". Add TNMUDP control, the Name property is set to "SUDP"; the localport property is set to "2222", allows the control SUDP to monitor the 2222 port of the master, and trigger the control SUDP's OnDataReceIVed event; RemotePort property For "1111", when the control SUDP sends data, the data is sent to the 1111 port of the controlled machine. Add the control image1, the align property is set to "AlClient"; add the control button1, the CAPTION property is set to "Screen capture"; add the control Label1, the CAPTION property is set to "Left: upper: Right: Next"; join the control Edit1, the TEXT property is set to "0: 0: 100: 100"; join the control Label2, the CAPTION property is set to "Controller IP Address"; add the control EDIT2, and the Text property is set to "127.0.0.1"; add variable definitions after IMPLEMentation, const bufsize = 2048 ; Var RsltStream, TmpStream: TMemoryStream;

Add code to Server's oncreate event: Procedure TSERVER.FORMCREATE (Sender: TOBJECT); Begin RsltStream: = tmemorystream.create; tMPStream: = tmemorystream.create;

Add code to the Client OnDestroy event: procedure TServer.FormDestroy (Sender: TObject); begin RsltStream.Free; TmpStream.Free; end; add the code for the OnClick event of the control of Button1: procedure TServer.Button1Click (Sender: TObject); var ReqCode : array [0..29] of char; ReqCodeStr: string; begin ReqCodeStr: = 'show' Edit1.Text; StrpCopy (ReqCode, ReqCodeStr); TmpStream.Clear; RsltStream.Clear; SUDP.RemoteHost: = Edit2.Text Sudp.sendBuffer (Reqcode, 30);

SUDP OnDataReceived add event control code: procedure TServer.SUDPDataReceived (Sender: TComponent; NumberBytes: Integer; FromIP: String); var ReqCode: array [0..29] of char; ReqCodeStr: string; begin ReqCodeStr: = 'show ' Edit1.text; StrpCopy (ReqCode, ReqCodeStr); SUDP.ReadStream (TmpStream); RsltStream.CopyFrom (TmpStream, NumberBytes); if NumberBytes

Save "C: /VServer/svrunit.pas" and "C: /VServer/vser.dpr" and compiled.

---- Fourth, test. ---- 1, Local Test: The screen capture can be implemented using the user's default settings at the same time. View "Control Panel" - "Network" - "TCP / IP" - "IP Address", set the "Customer IP Address" of the program to this address, which is equally normal.

---- 2, Remote Test: Choose a controlled machine, run vclient.exe; choose one master, run VServer.exe, set "controlled machine IP address", EDIT2, set to controlled The IP address of the machine, "screen capture". The above is briefly introduced the implementation method of the remote screen, as for monitoring multiple controlled machines at the same time on the main control machine, readers can improve themselves. The above procedures, in Windows98 peer, Delphi 4.0 debugging.

转载请注明原文地址:https://www.9cbs.com/read-3847.html

New Post(0)