PDA

View Full Version : C# sample code


Sefai
January 17, 2004, 16:33:26
Hi all,

I have downloaded ActiceX 10.1 trial, and I am trying to convert the script in the minutes sample to C# code in a CS file without success.

I am developing a webservice and my procedure is too complicated, so I can`t and don`t want to write a script.

Please send me a sample.

Meik Dankleff
January 20, 2004, 18:42:03
Please let me know, which minutes sample you mean?

Sefai
January 21, 2004, 15:11:15
I solved the problem, and I am sending the code as an example for others.
But there is one point still I am confused about. I create the control and License manager by "new" keyword, but there is no destructor for both objects,
won't this lead to a memory overload and low performance. Because this will work in a .Net Web Service and this function will be called a lot of times.
Can nullifying solve this problem, e.g, txTextControl = null?
public byte[] DoChangeNumber(byte []bData, int iDepCode, int iFoundCode)
{
// This is important point 1
Tx4oleLib.ILicManager licenceManager = new Tx4oleLib.TXLicenseManagerClass();
Tx4oleLib.TXTextControl txTextControl = new Tx4oleLib.TXTextControl();
// This is important point 2
txTextControl.EnableAutomationServer();
txTextControl.ResetContents();

// This is important point 3
txTextControl.ViewMode = 2;

// This is important point 4
txTextControl.PageHeight = 16837;
txTextControl.PageWidth = 11906;
txTextControl.PageMarginL = 567;
txTextControl.PageMarginB = 567;
txTextControl.PageMarginT = 567;
txTextControl.PageMarginR = 567;

txTextControl.LoadFromMemory(bData, 5, 0);

short nFieldID = txTextControl.FieldNext(0, 0);

do
{
txTextControl.FieldCurrent = nFieldID;
if (nFieldID == 2)
break;

nFieldID = txTextControl.FieldNext(nFieldID, 0);
}
while (nFieldID != 0);

string s = txTextControl.FieldText;

s = s.Replace("BN", iDepCode.ToString()).Replace("KN", iFoundCode.ToString());

short nTableID = txTextControl.TableAtInputPos;

txTextControl.set_TableCellText(nTableID, 1, 3, s);


// This is the most important part, if you don't supply an initialized array an exception occurs
byte []bNewData = new byte[1];
bNewData = (byte[])txTextControl.SaveToMemoryBuffer(bNewData, 12, 0);
return bNewData;
}

Meik Dankleff
January 22, 2004, 17:22:12
I am not that familiar with C#, but as it is a lot like Java, I think the objects will be garbage collected as soon as all references are cleared/nullified.

Sefai
January 23, 2004, 17:33:51
Attention

"short nTableID = txTextControl.TableAtInputPos;"

works for Windows applications, but return "-32768" for web applications. So in a web application, directly changing the field text will be the solution.

"txTextControl.FieldText = s;"

And Meik, is this a bug? Or do you have an acceptable explanation about this?