Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / All-Topics

Discovering D and Visual Studio (continued…)

5.00/5 (3 votes)
31 May 2011CPOL3 min read 13.8K  
CodeProjectThanks for the feedback from the previous article, I know now that: DFL should work with the BCL in D2, but it just doesn’t at the moment, due to some repository snafu… Visual D had building problem due to… tool chain issues! This page about Visual D known issues explain what

Thanks for the feedback from the previous article, I know now that:

  • DFL should work with the BCL in D2, but it just doesn’t at the moment, due to some repository snafu…
  • Visual D had building problem due to… tool chain issues! This page about Visual D known issues explain what’s going on and how to fix it!

Hence by modifying C:\D\dmd2\windows\bin\sc.ini

To be like (changes in maroon)

[Version]
version=7.51 Build 020

[Environment]
LIB="%@P%\..\lib";\dm\lib;%DMD_LIB% DFLAGS="-I%@P%\..\..\src\phobos" "-I%@P%\..\..\src\druntime\import"
LINKCMD=%@P%\link.exe

 

I was able to make do with a much more satisfactory config:

image

 

Community support

Maybe I should mention that D, despite being a marginal language (as in: little know) has a surprisingly pleasantly vibrant community support.

Also the Digitalmars page on D is full of interesting link (particularly Tools => More Tools) but I’d like to grab the attention on 2 communities:

  • D Source forums
  • Digitalmars newsgroups (news server: news.digitalmars.com). Can be accessed with Windows Live Mail or Thunderbird for example. Just create a new newsgroup account

    image

 

Initial sample reloaded

I though it might be a good idea to have DGui in my projects (i.e. as source code / solution’s project) and link my test project against it. This way I can look, play with and learn from some D code written by a more knowledgeable D programmer than I!

It turns out there are key difference with what would happen with trying to do that with C#. Perhaps it behave like it will with Visual C++, I couldn’t tell, not having using it enough…

At any rate here is what happened

  • I created a new Visual D static library
  • Created the directory hierarchy of the DGui source (it’s important for D, just like Java, it reflects package organisation)
  • Added the existing file from DGui
  • And build, successfully first try! (Nicely enough DGui has no other dependency that Phobos / BCL)

image

Now, when looking at the file system, there was no D file in my project’s directory! All these files in the solution explorer linked to the one and only original files.

Hence, I shouldn’t change the import file path of my test project. For the record they remained pointing to
C:\D\dgui

image

 

 

Updating the dependencies

But I still needed to point to my build version of DGui, hence change the library path of my test project. And I also need to set my test project to depends on my (local) dgui project.

Right click on project => Project dependencies => select dgui

 

image image

Set the library search path to the project build location: C:\Dev\DTest\dgui\Debug.

image

F5, it builds and run!

Now for the surprisingly good part, in my test app, if I F12 on one of the class I use, VS actually goes there!

But no method list (yet?).

Just for fun I added a “std.stdio.writeln("hello");” in initialization looking method (I still knows nothing of D, hey!) and .. it printed!

 

Getting rid of the console

I’m trying a GUI sample, yet I have a nagging MS-Dos console appearing every time I run. To get rid of it I should pass a special flags to the linker (in Additional options) so it will mark the executable as being a windows application (i.e. no console attached!)

-L/SUBSYSTEM:windows:4

image

 

 

A brief look at the source code

So far I haven’t coded anything yet! Just wanted to feel comfortable with the development experience… But will post about source code next time!

Anyhow, below is the source code of my test app (straight from events.d in DGui’s samples):

module events;

import dgui.all;

class MainForm: Form
{
    private Button _btnOk;
    
    public this()
    {
        this.text = "DGui Events";
        this<.size = Size(300, 250);
        this.startPosition = FormStartPosition.CENTER_SCREEN; // Set Form Position
        
        this._btnOk = new Button();
        this._btnOk.text = "Click Me!";
        this._btnOk.dock = DockStyle.FILL; // Fill the whole form area
        this._btnOk.parent = this;
        this._btnOk.click.attach(&this.onBtnOkClick); //Attach the click event with the selected procedure
    }
    
    private void onBtnOkClick(Control sender, EventArgs e)
    {
        // Display a message box
        MsgBox.show("OnClick", "Button.onClick()");
    }
}

int main(string[] args)
{
    return Application.run(new MainForm()); // Start the application
}     

The exciting things I can see from a quick look at the source is that D supports properties, events and DGui looks quite similar to WinForm!

Except for the lack (at the moment) of designer Sad smile 

Ho well, I just plan to make simple wizards anyway…

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)