|
I read your article on String Creator recently and now wanted to go back to it....it seems to have disappeared...searching for your name or the name of the app does not bring up the article. Where are you???
|
|
|
|
|
|
Hi,
I'm just wondering whether I'm on the right way or not. I'd like to create a typesafe collection. The data should be held in an ArrayList for simplicity. For all my collection-classes I'd like to create a base class (say MyCollectionBase) which implements all functionality which is not related to the objects-types contained in this collection. For a start, I thought about something like this:
public class ColBase : IEnumerable {<br />
public ColBase() {}<br />
<br />
public IEnumerator GetEnumerator() {<br />
return mData.GetEnumerator();<br />
}<br />
<br />
public virtual int Count() {<br />
return mData.Count;<br />
}<br />
<br />
public virtual void Clear() {<br />
mData.Clear();<br />
} <br />
<br />
protected ArrayList mData = new ArrayList();<br />
}
So far so good. Now the derived classes support the foreach syntax which is what I wanted. The derived classes have to implement their versions of Add(), AddRange(), Remove(), etc, like (say we have a class called Item which represents the individual items in the collection):
public class Col : ColBase {<br />
public Col() {}<br />
<br />
public Item Add(Item item) {<br />
return (Item) base.mData[base.mData.Add(item)];<br />
}<br />
<br />
public void Remove(Item item) {<br />
base.mData.Remove(item);<br />
}<br />
}
But my Baseclass does not support the [] indexer. How do I have to implement this? Am I on the right way or should this be done completely different?
Thanks for comments...
Matthias
If eell I ,nust draw to your atenttion to het fakt that I can splel perfrectly well - i;ts my typeying that sukcs.
(Lounge/David Wulff)
www.emvoid.de
|
|
|
|
|
Take a look at the CollectionBase . It already has two properties - both protected - to access the underlying ArrayList . It also has On* methods defined that will be called when you use the List property, but they will not be called when you use the InnerList property. This is handy if you want to define events for when the collection changes.
It's a good starting point for a typed collection, since you can define the methods that take a typed object (whatever type you're collecting) and call the explicit interface methods (like IList.Add ), so that it appears as a typed collection. Explicit interface methods are how many classes in the .NET Framework Class Library - including classes in System.Data.* and System.Collections.* - appear to take a specific type as a parameter even though they implement interfaces that must access an object .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
After you inherit from an interface (ex:IList) that has the indexer try the following.
new public ColBase this[int index] {
get {
return (ColBase ) base[index];
}
set {
base[index] = value;
}
}
|
|
|
|
|
I found really nice collection generator:
http://kristopherjohnson.net/cgi-bin/twiki/view/KJ/TypedCollectionGenerator
it works pretty well, just install it as a tool in VS and you can have typed collection in a second.
|
|
|
|
|
Hi All,
I created an application that navigate over the html pages, saving them. I have found a problem about the conversion from IHTMLDocument2 document to UCOMIPersistFile.
Based on the following code:
IHTMLDocument2 docToSave = (IHTMLDocument2) axWebBrowser2.Document;
UCOMIPersistFile pf = (UCOMIPersistFile) docToSave;
pf.Save(PathMi + "\\html\\" + page + ".htm",true);
After the last instrucción, the applicacion does a click() method on a ancher tag to navigate to the next page, the problem is that de Url of the document has been change to path pass at th pf.save method, and I dont know how can I change it again.
(I have to save using the UCOMIPersistFile class, no other kind of files)
Any ideas ???
|
|
|
|
|
Instead of saving this yourself, you might try invoking AxWebBrowser.ExecWB with OLECMDID_SAVEAS (value == 4) as the first parameter, plus any parameters required by the call, which are documented in the IWebBrowser2 interface documentation on MSDN[^].
Using this, you can have the browser save the page - including (almost - depends on the complexity of the page, but it usually works) all embedded content (stylesheets, images, javascript files, etc.). You can do this with or without a UI. This is exactly the same as invoking the File-<Save As command in Internet Explorer.
The URL of the document is changing because you've changed it's reference to the file you've saved.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I have this code:
<br />
private void BuildMaterialsAssembly ( string MaterialsSourceFile )<br />
{<br />
StreamReader srcReader = new StreamReader ( MaterialsSourceFile );<br />
string materialSource = srcReader.ReadToEnd (); <br />
srcReader.Close ();<br />
<br />
CSharpCodeProvider codeProvider = new CSharpCodeProvider ();<br />
ICodeCompiler icc = codeProvider.CreateCompiler ();<br />
<br />
<br />
CompilerParameters parameters = new CompilerParameters ();<br />
parameters.GenerateExecutable = true;<br />
parameters.OutputAssembly = "e:\\jan\\mat\\dllll.exe";
<br />
CompilerResults results = icc.CompileAssemblyFromSource ( parameters, materialSource );<br />
}<br />
The problem is that this code refuses to compile an assembly (DLL), it does nothing. It dosen't matter if the soruce is a regular text file with no C# code what so ever, or a perfectly vaild C# (library) code.
I copied this from MSDN and did a few changes.
What coudl possibly be wrong?
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
problem solved, I need to add asembly refrences.
But, why didn't I get any exceptions??
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
I've created a round button...can someone please tell me how to add embossed effect to this....i mean when i click on the button it functions well but i wanted to get the feel of the button..now it looks just like a picture which works as a button....
Any other advice and articles on Custom controls would also be just great..
Thnx
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!THINK FREE!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
Change your pictures to "look" 3D, or your drawing code, whichever your using to show the image of a button. You'll need to change both the button up and button down images.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Is there anyother way to set the default button flat style standard to work...
I mean your suggestion sounds like changing the image or the circle to look 3D....i wanted to know if something can be dont to give it the natural embossed button effect..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!THINK FREE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
Once you dtart supplying your own images, you have to also start supplying your own styles to them. You'd use two images, one for the button unpressed, and another for the button pressed. You can't use the standard styles on button images that you supply. The control has no way of determining where the edges of your button images are.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
C# or JavaME? Which one is better for pocket PC game development?
|
|
|
|
|
A lot of Java games run on mobile devices. but Java is slow,while C# maybe faster than Java. but it needs time proving.
fay
|
|
|
|
|
whatever you want, they both have their pros and cons. C# would be funner though.
/\ |_ E X E GG
|
|
|
|
|
Question Title: Marshalling Return type as LPArray
Author: ranadhir
Points: 80
Date: 06/17/2004 06:41PM PDT
I have a COM client calling invoking a function on a managed library.The interface definition is
[return :MarshalAs(UnmanagedType.LPArray,SizeParamIndex=0)] int[] returnTemperatureAsArray(out int cnt);
When i invoke is from ATL client as follows
long _elem;
long* ptemp=NULL;
ptemp=cpi->returnTemperatureAsArray(&_elem);
I get a runtime debugger error
*********************************************************************************************
The value of ESP was not properly saved across a function call.This is usually a result of calling a function declared with one calling convention with a function pointer decalred with a differenct calling convention.
**********************************************************************************************
I tried invoking the same function from a COM dll,and it works fine.Here is a excerpt from the type libraries (as viewd in oleview)
1.Managed typelib
interface IWeatherSink : IUnknown {
HRESULT _stdcall returnTemperatureAsArray(
[out] long* cnt,
[out, retval] long** pRetVal);
};
2.COM DLL typelib
interface ICheckFunctionCalls : IUnknown {
[helpstring("method returnLongAsArray")]
HRESULT _stdcall returnLongAsArray(
[out] long* pcount,
[out, retval] long** pArr);
};
However if i make the array a out parameter rather than a return type , it works fine.
What is wrong?Is this invocation not allowed from managed code?What should I do to make this invocation succeed?
|
|
|
|
|
COM decrees that you always return an HRESULT from a method or property. Automation clients like VB and, to some degree .NET, translate retvals to return values for you. This can be controlled with the PreserveSigAttribute (although that's for RCWs, not CCWs like you're using here). So your cpi->returnTemperatureArray call should accept an [out, retval] as the last parameter and return an HRESULT (which .NET will for you based on whether or not you thrown an exception, or if you preserve the signature and return an error or success code).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
If you care in the description on your "Custom String Formatting in .NET" there is a 't' floating around....
You might want to fix it... you know the short description under the title on the topish....
/\ |_ E X E GG
|
|
|
|
|
Thanks. I'll get that fixed.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
So what i understand is that there is no way that a function with the following signature
in a C# DLL ,can be invoked by a win32/ATL client
[return :MarshalAs(UnmanagedType.LPArray)] int[] returnTemperatureAsArray(out int cnt);
Why do i not get this error with the following then ?
[return : MarshalAs(UnmanagedType.LPStr)] string GetWeatherAsANSI();
This seems to work fine when invoked from a win32 client.
|
|
|
|
|
You can, but the CCW (COM-Callable Wrapper) changes the int[] return value into an [out, retval] parameter at the end of the method, as it should be in COM since all methods (including property getter and putters) should return an HRESULT .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
What is the fastest way to render raw image bits to a Bitmap Object? I am not allowed to use unsafe code.
|
|
|
|
|
You mean basically what you'd pass to CreateDIBSection in Windows GDI? Well, you must know a few things about the bitmap data, like the width and height, or even just the stride (how many bytes in a line). You also need to know the pixel format, such as whether the data represents a 32-bit bitmap, 24-bit, etc.
Fortunately, with this information GDI+ (and System.Graphics ) makes this easy. Use the Bitmap(int, int, int, PixelFormat, IntPtr) constructor, which takes the width, height, stride, pixel format, and a pointer to the raw data, respectively.
Read more about that constructor in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|