Golang Binding VCL Components

Source: Internet
Author: User
Tags manual writing
This is a creation in Article, where the information may have evolved or changed.

Project description

Currently the project only supports Windows (support Win32, Win64), but the code is written with the help of the CROSSVCL implementation of Linux and Mac OS support, but the temporary CROSSVCL in the Dylib directly create an error, so the cross-platform this block temporarily stopped development.

The warehouse does not submit the entity code (at least not at the moment), the code exists in the OSC private project, not yet complete the entire project, some need to be modified, follow the situation to open source bar.

Instance class description

* * According to the Delphi application, screen, Mouse, clipboard Four class instances are directly accessible, do not need to release
In fact, the component with the Onwer parameter of the general designation Tfrom, so that there is no need to manually release, and the owner
Writing nil requires you to call free manually, just like any other non-component class. **

Now supports the list of components and non-component classes:

Tapplication
Tform
TButton
Tedit
Tmainmenu
Tpopupmenu
TMemo
Tcheckbox
Tradiobutton
Tgroupbox
Tlabel
Tlistbox
Tcombobox
Tpanel
Timage
Tlinklabel
Tspeedbutton
Tsplitter
Tradiogroup
Tstatictext
Tcolorbox
Tcolorlistbox
Ttrayicon
Tballoonhint
Tcategorypanelgroup
Topendialog
Tsavedialog
Tcolordialog
Tfontdialog
Tprintdialog
Topenpicturedialog
Tsavepicturedialog
Tsavetextfiledialog
Topentextfiledialog
Trichedit
Ttrackbar
Timagelist
Tupdown
Tprogressbar
Thotkey
Tdatetimepicker
Tmonthcalendar
TListView
Ttreeview
Tstatusbar
Ttoolbar
Tpagecontrol
Ttabsheet
Tcontroltactionlist
Ttoolbutton

Ticon
Tbitmap
Tmemorystream
TFont
TStrings
Tstringlist
Tbrush
Tpen
Tmenuitem
Tlistgroups
Tpicture
Tlistcolumns
Tlistitems
Ttreenodes
Tlistitem
Ttreenode
Tscreen
Tmouse
Tlistgroup
Tlistcolumn
Tcollectionitem
Tstatuspanels
Tstatuspanel
Tcanvas
TObject
Tpngimage
Tjpegimage
Tgifimage
Tgifframe
Tinifile
Tregistry
Tclipboard

* * Manual writing with def after file name * *

code example

GOVCL Project Main.gopackage main//Windows compile identity//Go.exe build-i-ldflags= "-H Windowsgui" Import ("FMT"//Import project path here) var (MainForm *VCL. Tformtrayicon *VCL. Ttrayicon) Func Main () {///exception Capture defer func () {err: = recover () if err! = Nil {fmt. Println ("Exception:", err) vcl. ShowMessage (Err. ( Error). Error ())}} ()//rtl. Setreportmemoryleaksonshutdown (True) fmt. Println ("main") Icon: = VCL. Newicon ()//icon. LoadFromFile ("0.ico") icon. Loadfromresourceid (RTL. Maininstance (), 3) defer icon. Free () vcl. Application.initialize () vcl. Application.seticon (icon) vcl. Application.settitle ("Hello world!") Vcl. Application.setmainformontaskbar (true) MainForm = VCL. Application.createform () mainform.setwidth (mainform.setheight) Mainform.setonclose (func (Sender vcl). Iobject, Action uintptr) {fmt. Println ("Close")}) Mainform.setonclosequery (func (Sender vcl). Iobject, Canclose uintptr) {//rtl. Formsetcanclose (Canclose, False) Fmt. Println ("Onclosequery")}) Mainform.setcaption (VCL. Application.title ()) Mainform.enabledmaximize (false) MainfoRm. Setdoublebuffered (true) TrayIcon = VCL. Newtrayicon (mainform) TrayIcon. SetIcon (icon) TrayIcon. Sethint (Mainform.caption ()) TrayIcon. SetVisible (True) TrayIcon. Setonclick (func (VCL). Iobject) {TrayIcon. Setballoontitle ("Test") TrayIcon. Setballoontimeout (10000) TrayIcon. Setballoonhint ("I am the cue body") TrayIcon. Showballoonhint () fmt. Println ("TrayIcon click.")}) Imgimg: = vcl. NewImage (MainForm) img. SetBounds (156, +, +) img. SetParent (MainForm) img. Picture (). LoadFromFile (". \\imgs\\1.jpg")//img. Setstretch (True) img. Setproportional (TRUE)//LINKLABELLINKLBL: = VCL. Newlinklabel (mainform) linklbl. Setalign (API. Albottom) Linklbl. Setcaption ("<a href=\" http://www.baidu.com\ "> Test Links </a>") Linklbl. SetParent (mainform) linklbl. Setonlinkclick (func (Sender vcl). Iobject, link String, linktype int32) {fmt. PRINTLN ("link label:", Link, ", type:", Linktype)})//Menumainmenu: = VCL. Newmainmenu (mainform) Item: = VCL. Newmenuitem (MainForm) item. Setcaption ("File (&f)") Mainmenu.items (). ADD (item) ITEM2: = VCL. Newmenuitem (MainForm) item2. Setcaption ("Memorystreamtest") item2. Setonclick (func (VCL). Iobject) {mem: = VCL. Newmemorystream () Defer mem. Free () s: = API. Gostrtodstr ("Ffff F") mem. Write (S, Int32 (API). Dstrlen (s) *) mem. SaveToFile ("Test.txt")}) item. ADD (item2) item2 = vcl. Newmenuitem (mainform) item2. Setcaption ("Exit (&e)") item2. Setshortcutfromstring ("Ctrl+q") item2. Setonclick (func (VCL). Iobject) {mainform.close ()}) item. ADD (ITEM2)//mainform.enabledminimize (False)//mainform.enabledsystemmenu (false) button: = VCL. Newbutton (mainform) button. Setcaption ("message") button. SetParent (mainform) button. Setonclick (func (VCL). Iobject) {fmt. Println ("button click") vcl. ShowMessage ("This is a message") VCL. Application.messagebox ("hello!", "Message", win. Mb_yesno+win. mb_iconinformation)}) button. Setleft () button. Settop () button. Setalign (API. Alright) Edit: = vcl. Newedit (mainform) edit. SetParent (mainform) edit. Setleft (1) Edit. Settop (+) edit. Settexthint ("Test") edit. Setonchange (func (VCL). Iobject) {fmt. Println ("Edit OnChange")}) Button2: = VCL. Newbutton (mainform) ButtoN2. SetParent (mainform) button2. Setcaption ("a") button2. SetWidth (button2). SetHeight (button2). Setonclick (func (VCL). Iobject) {fmt. Println ("Button2 click") edit. SetText ("hello!") Fmt. Println ("ScreenWidth:", VCL.) Screen.width (), ", ScreenHeight:", VCL. Screen.height ())}) button2. Setalign (API. Altop) Chk: = VCL. Newcheckbox (mainform) chk. SetParent (mainform) chk. Setchecked (True) chk. Setcaption ("Test") chk. Setleft (1) chk. Settop () chk. Setonclick (func (VCL). Iobject) {fmt. Println ("Chk. Checked= ", chk. Checked ())}) Combo: = VCL. Newcombobox (mainform) combo. Setalign (API. Albottom) Combo. SetParent (mainform) combo. SetText ("FFFF") combo. Items (). ADD ("1") combo. Items (). ADD ("2") combo. Setitemindex (0) combo. Setonchange (func (VCL). Iobject) {if combo. ItemIndex ()! =-1 {fmt. PRINTLN ("Combo Change:", combo. Items (). Strings (combo. ItemIndex ())}}) Page: = VCL. Newpagecontrol (mainform) page. SetParent (mainform) page. Setalign (API. Albottom) Sheet: = vcl. Newtabsheet (mainform) sheet. Setpagecontrol (page) sheet. Setcaption ("first page")//need to set tabsheet parent window first, TlisTview only available, otherwise it will error LV1: = VCL. Newlistview (mainform) lv1. Setalign (API. alclient) Lv1. SetParent (sheet) lv1. Setviewstyle (API. VSReport) Lv1. Setrowselect (True) lv1. Setreadonly (True) lv1. Setgridlines (True) col: = Lv1. Columns (). Add () Col. Setcaption ("serial number") Col. SetWidth (+) col = lv1. Columns (). Add () Col. Setcaption ("name") Col. SetWidth (LV1). Setonclick (func (VCL). Iobject) {if lv1. ItemIndex ()! =-1 {fmt. Println (LV1. Items (). Item (LV1. ItemIndex ()). Caption ())}}) Lv1. Items (). BeginUpdate () for I: = 1; I <= 50; i++ {lstitem: = Lv1. Items (). ADD () Lstitem. Setcaption (FMT. Sprintf ("%d", i)) Lstitem. SubItems (). ADD (FMT. Sprintf ("%d", i))}lv1. Items (). EndUpdate () sheet = vcl. Newtabsheet (mainform) sheet. Setcaption ("second page") sheet. Setpagecontrol (page) TV1: = VCL. Newtreeview (mainform) TV1. SetParent (sheet) TV1. Setalign (API. alclient) TV1. Items (). AddChild (Nil, "first") Mainform.screencenter () vcl. Application.Run ()}
Related Article

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: info-contact@alibabacloud.com 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.