Git Product home page Git Product logo

Comments (4)

ying32 avatar ying32 commented on August 15, 2024

Switch to dev branch, then:

package main

import (
	"github.com/ying32/govcl/vcl"
)

var (
	mainForm *vcl.TForm
)

// ControlType is the variable used as an enum
type ControlType int

const (
	Label ControlType = 1 + iota
	Button
)

type Form struct {
	*vcl.TForm
}

func main() {
	vcl.Application.Initialize()
	mainForm = vcl.Application.CreateForm()
	mainForm.SetCaption("Hello to you!!")
	mainForm.ScreenCenter()
	AddLabel(mainForm, mainForm, 10, 10, 100, 22, "A functional label!")
	AddButton(mainForm, mainForm, 10, 40, 40, 20, "Click Me!")
	vcl.Application.Run()
}

// AddLabel adds a new Label
func AddLabel(owner vcl.IComponent, parent vcl.IWinControl, left int32, top int32, width int32, height int32, caption string) *vcl.TLabel {
	label := CreateControl(owner, Label)
	label.SetParent(parent)
	label.SetBounds(left, top, width, height)
	label.SetCaption(caption)
	return label.(*vcl.TLabel)
}

// AddButton adds a new button
func AddButton(owner vcl.IComponent, parent vcl.IWinControl, left int32, top int32, width int32, height int32, caption string) *vcl.TButton {
	button := CreateControl(owner, Button)
	button.SetParent(parent)
	button.SetBounds(left, top, width, height)
	button.SetCaption(caption)
	return button.(*vcl.TButton)
}

// CreateControl is a "Generic" factory method for Control creation
func CreateControl(owner vcl.IComponent, controlType ControlType) vcl.IControl {
	switch controlType {
	case Label:
		return vcl.NewLabel(owner)
	case Button:
		return vcl.NewButton(owner)
	default:
		return nil
	}
}

You can use the res2go tool to convert Delphi or Lazarus form resource files.

from govcl.

carlca avatar carlca commented on August 15, 2024

I am not greatly experienced with Git, but I did

git checkout dev

I updated my code to match your changes, then tried to build it again. I got...

./main.go:36:7: label.SetParent undefined (type vcl.IControl has no field or method SetParent)
./main.go:38:7: label.SetCaption undefined (type vcl.IControl has no field or method SetCaption)
./main.go:45:8: button.SetParent undefined (type vcl.IControl has no field or method SetParent)
./main.go:47:8: button.SetCaption undefined (type vcl.IControl has no field or method SetCaption)

I expect I've made a mistake on the Git side of things!

from govcl.

ying32 avatar ying32 commented on August 15, 2024

′git pull′

from govcl.

carlca avatar carlca commented on August 15, 2024

git pull worked fine. Thanks for the changes, they work perfectly!

from govcl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.