Delphi-errorcode Query

Source: Internet
Author: User

Technical Exchange, DH.

We usually use getlasterror to obtain error information after calling some APIs, but the information is all integer. Do we know what it means?
Hey, yes, there is msdn. Of course, you can also use the formatmessage function.
Let's take a look at the example in the first chapter of Windows core programming and try it with Delphi.
The formatmessage function is mainly used. There are many usage and precautions. You can refer to msdn.

Unit utmain; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, cxgraphics, cxcontrols, controls, containers, cxcontainer, cxedit, dxskinscore, keys, cxgroupbox, cxcheckbox, cxtextedit, audit, cxlabel, menus, cxmemo, stdctrls, cxbuttons; Type tform3 = Class (tform) cxlbl1: tcxlabel; Role: role; cxtxtcode: role; Role: tcxcheckbox; kgdescription: tcxgroupbox; btnsearch: tcxbutton; cxmdescription: pushed; Procedure btnsearchclick (Sender: tobject); Procedure destroy (Sender: tobject); Private {private Declarations} dwcode: Cardinal; systemlocale: cardinal; Public {public declarations} end; var form3: tform3; implementation {$ R *. DFM} procedure tform3.btnsearchclick (Sender: tobject); var B: Cardinal; hlib: Cardinal; Buf: pchar; begin if cxchkhex. checked then dwcode: = strtointdef ('$' + cxtxtcode. text, 0) else dwcode: = strtointdef (cxtxtcode. text, 0); getmem (BUF, 256); try // get B: = formatmessage (format_message_from_system, nil, dwcode, systemlocale, Buf, 255, nil ); // if no network-related if B = 0 then begin hlib: = LoadLibraryEx ('netmsg. dll ', 0, dont_resolve_dll_references); try assert (hlib <> 0); B: = formatmessage (format_message_from_hmodule, pointer (hlib), dwcode, systemlocale, Buf, 255, nil ); finally if hlib <> 0 then freelibrary (hlib); end; If (B <> 0) Then cxmdescription. text: = Buf else cxmdescription. text: = 'the Error Code cannot be found '; finally freemem (BUF); end; Procedure tform3.formcreate (Sender: tobject); begin // set the language to the default systemlocale: = makelangid (lang_neutral, sublang_default) end; end.

for the sake of DX skin, I used the devexpress control but did not use other functions of the control. If Dev is not installed, you can replace them with the most common buttons.
here is an image:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.