GLL Example: Add a Resource

Add a resource to :Files section using Gfa_CopyFile.

This example shows a way to add a resource file to the inline section on the :Files tab. It assumes you put the filename of the resource in the source code in the following format.

//:icodeb = e:\cparse\icodeb.ico

// The GLL sub (Shift + Ctrl + C) to handle the copy process is here.

 

Sub Gfa_Ex_C

Local a$, b$, i%

a = Trim(Gfa_Text)

If Left(a, 3) != "//:" Then Exit Sub

a = Mid(a, 3)

i = InStr(a, "=")

If !i Then Exit Sub

b = LTrim(Mid(a, i + 1))

a = RTrim(Left(a, i - 1))

If Len(b) == 0 || Len(a) <= 1 Then Exit Sub

If Exist(a)

MsgBox a & " exists"

Exit Sub

EndIf

Try

Gfa_CopyFile b, a

Catch

MsgBox "Error while copying"#10"from " & b & " to " & a

EndCatch

End Sub

When the cursor is located in the line starting with a //: comment, the comment is analyzed to look for a resource to be added to the inline section. The name of the inline resource is specified with the string starting with the colon (:icon1). Then the line searched for the name of the file to load, which must be preceded with ' = '. If the file doesn't exist a message is displayed, otherwise the file is copied to the inline section using Gfa_CopyFile.

This example can be extended by overriding the previous inline entry. However, the inline resource must de deleted first. To delete the :File use Gfa_CopyFile "", when Exist(a) is true.

{Created by Sjouke Hamstra; Last updated: 08/10/2014 by James Gaite}