|
Thanks Hogan,
Question answered.
regards,
George
|
|
|
|
|
You need to do what is called an explicit implementation of the interface. Here is the syntax using your example:
public interface IFoo
{
object Abc();
}
public class Foo : IFoo
{
public List<int> Abc()
{
return new List<int>();
}
object IFoo.Abc()
{
return this.Abc();
}
}
|
|
|
|
|
Thanks tgrt!
regards,
George
|
|
|
|
|
|
Let's say I have a resource broker, a 'lookup resource' event and a main program that will invoke the lookup resource event. All of these reside in decoupled modules, there may be only one resource broker and of course only one lookup event definition.
I created the following classes to implement the situation above:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Program::Main");
EventBroker.Current.FireLookupResource(null, EventArgs.Empty);
Console.ReadLine();
}
}
public class EventBroker
{
private static readonly EventBroker _current = new EventBroker();
public static EventBroker Current { get { return _current; } }
public event EventHandler LookupResource;
private EventBroker() { }
public void FireLookupResource(object sender, EventArgs args)
{
Console.WriteLine("EventBroker::FireLookupResource");
if (LookupResource != null)
LookupResource(sender, args);
}
}
public class ResourceBroker
{
private static readonly ResourceBroker _current = new ResourceBroker();
public static ResourceBroker Current { get { return _current; } }
private ResourceBroker()
{
Console.Write("ResourceBroker::ResourceBroker");
EventBroker.Current.LookupResource += EventBroker_LookupResource;
}
private static void EventBroker_LookupResource(object sender, EventArgs e)
{
Console.Write("ResourceBroker::EventBroker_LookupResource");
}
}
However the output is not what I expected: the LookupResource event never gets called. That's understandable, since the ResourceBroker never gets referred in the executing code, it will not get instantiated. But what should I do to get the 'correct' output?
Creating a NoOp method in the ResourceBroker, and calling it in the Main function, works but it seems to me like an ugly hack. Am I missing something in the language keywords/features?
Thanks in advance
Luca
The Price of Freedom is Eternal Vigilance. -- Wing Commander IV
En Það Besta Sem Guð Hefur Skapað, Er Nýr Dagur.
(But the best thing God has created, is a New Day.)
-- Sigur Ròs - Viðrar vel til loftárása
|
|
|
|
|
Hmmmm... This is a bit of a tricky situation. Usually when I find myself in this situation, it means it's time to do a redesign. As a suggestion, you may want to make a BrokerManager that does all of the initialization for you, or pick an appropriate Broker class and have it take an instance of the other as a constructor argument. You can limit the instances that way, and you may be able to do away with the singleton pattern. Hope that helps somewhat.
Scott P
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Hi ,
i have try to open an PDF file in windows application using C# I was getting an error that type should not be null following is the code . Please Help me Urgent.
Acrobat.CAcroApp app = (Acrobat.CAcroApp)Activator.CreateInstance(Type.GetTypeFromProgID("AcroExch.App"));
app.Show();
Acrobat.CAcroAVDoc doc = (Acrobat.CAcroAVDoc)Activator.CreateInstance(Type.GetTypeFromProgID("AcroExch.AVDoc"));
doc.Open(FileName, "Computed Mileage");
Error Message is
Value cannot be null.
Parameter name: type
Thank u ,
Maruthi.
|
|
|
|
|
My guess is that Type.GetTypeFromProgID is returning a null. Try seperating this out a bit and setting a couple of checks / breakpoints to try and find out more about what's going on:
Type acroapp = Type.GetTypeFromProgID("AcroExch.AcroExch");
Type acrodoc = Type.GetTypeFromProgID("AcroExch.AVDoc");
if ((acroapp == null) || (acrodoc == null))
throw new Exception("Acrobat not installed on this system.");
Acrobat.CAcroApp app = (Acrobat.CAcroApp)Activator.CreateInstance(acroapp);
Acrobat.CAcroAVDoc doc = (Acrobat.CAcroAVDoc)Activator.CreateInstance(acrodoc);
if ((app == null) || (doc == null))
throw new Exception("Error initialising Acrobat");
app.Show();
doc.Open(FileName, "Computing Mileage"); At least laying it out like this will tell you what's going wrong (or give you more of a hint).
If you see the first exception then check your TypeIDs for Acrobat, if you see the second then check the acrobat documentation is my only suggestion.
|
|
|
|
|
I have Adobe Reader 8.0 in my system But it was still showing null
even we want to install acrobat professional in my system
|
|
|
|
|
Where in the code I provided does it fail?
|
|
|
|
|
Now i Installed Acrobat Professional & try my code then it was showing another error at app.show();
Error is
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
& the code which u have give is still showing the same error type is null
|
|
|
|
|
maruthi wrote: showing the same error type is null
Which one? This is crucial.
|
|
|
|
|
Well I've got Acrobat Pro installed and AcroExch.AcroExch ProgID doesn't exist so you'll need to find out what that ID should be.
|
|
|
|
|
Another alternative way, much simpler would be:
System.Diagnostics.Process.Start(FileName); Which'll launch the default PDF viewer on the system with the specified file.
|
|
|
|
|
|
Hi,
I have to create exe that runs at Client side and Create VPN Connection automatically.
Plz prpvide solution quickly as soon as possible.
Thanx
Seema
|
|
|
|
|
Seema Gosain wrote: Plz prpvide solution quickly as soon as possible.
This is a tad rude. Your taking a job you can't do, is not our fault, we'll help when we're able.
I found this[^] with google, does it help ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
u can use dotras downloade its in sdk and try
|
|
|
|
|
hi frnds,
i tried the foll code 4 updatin in db its gettin updated but the current value is not gettin updated in datagrid only the old value is present in txtbox.. please help..im attachin the followin code.
private void Update_DataGrid(object source, DataGridCommandEventArgs e)
{
TextBox tb;
TextBox tb1
tb = (TextBox) e.Item.Cells[1].Controls[1]; // if i put 1 in controls only then its wrkin in .NET 03(is it bcoz of tat??)
empname = tb.Text;
tb1 = (TextBox) e.Item.Cells[2].Controls[1];
city = tb1.Text;
SqlCommand myCommand = new SqlCommand("sp_update",conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@empname",SqlDbType.VarChar,20));
command.Parameters.Add(new SqlParameter("@city",SqlDbType.VarChar,20));
command.Parameters["@empname"].Value = empname;
command.Parameters["@city"].Value = city;
connection.Open();
command.ExecuteNonQuery();
conn.Close();
Datagrid1.EditItemIndex = -1;
BindData();
}
|
|
|
|
|
This looks really messy, have you stepped through it to see what happens when it fails ? Do you need the Item.Cells.Controls code, because that really is nasty looking and seems fragile.
Is this a winforms app ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hello.
I have a small question/problem.
I have this text file:
0<br />
0 0 0 15 15 7
end<br />
<br />
1<br />
1 1 30 25 25 240 240 -1 5
end
I read it into an array in C#, but in my array I read it in as
0 0 0 15 15 7
1 1 30 25 25 240 240 -1 5
Since this is a easyer way of manipulating with the data, but now I want to save the data to the text file.
I know the line number of my array, but that does not add up with the orginal file since I stripped som things
So my question is: How do I save the manipulated data so it fits with the orginal data?
My code looks like this:
string[] SaveMonsterLines = File.ReadAllLines(XMLfileLocation);<br />
SaveMonsterLines[linenumber] = "1 1 30 25 25 240 240 -1 5 // 1";<br />
File.WriteAllLines(@"D:/output.txt", SaveMonsterLines);
If you dont understand my question/problem, please speak up 
|
|
|
|
|
If you throw away information, then you need to remember what it was, so you can restore it at the end. Or did I miss what you were asking ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
All right..
I will try to explain again
I have the array MonsterDataArray which contains the data from the text file
The array looks like this:
0 0 0 15 15 7 // 0
1 1 30 25 25 240 240 -1 5 // 1
And both of the lines above has a line number in the array which is 0 and 1
Now I changed something in my array. Lets say I changed line number 0
I changed it from:
0 0 0 15 15 7 // 0
to:
4 7 2 30 45 9 // bleh
Now the line number 0 is updated in the MonsterDataArray, but it is not updated in the text file
This is where my problem is.. I dont know how to save the changed line number 0 from my MonsterDataArray to my text file because if I use my current code the line number from my array doesnt match up with my text file since I removed some things
I hope this helps
|
|
|
|
|
Now I got the saving text working by not removing any data from the text file so my array looks like this:
0<br />
0 0 0 15 15 7
end<br />
<br />
1<br />
1 1 30 25 25 240 240 -1 5
end
But now I ran into another problem
I have a image where I draw ellipses on with the coordinates from my text file (X: 15 Y: 15 and the 2: X: 25, Y: 25). It triggers on the paint event from the image
I also have a mouse down event on my image
I save all my ellipses in a list called
List<rectangle> mapRectangleList = new List<rectangle>();</rectangle></rectangle>
When I do mouse down I see if the mouse is over a ellipse. If it is it jumps to a specific line in my MonsterDataArray, but the problem is when I save all my ellipses in the list I dont take end, 0, // and the other things from my text with. I only take:
1 0 30 25 25 240 240 -1 5
2 0 30 35 35 185 132 -1 10
So when I jump to specific line in my array the line doesnt match up
Yeah im kinda lost here..
Here is the mouse down part:
Point p = mapImage.PointToClient(Cursor.Position);<br />
<br />
for (int i = 0; i < mapRectangleList.Count; i++)<br />
{<br />
if (mapRectangleList[i].Contains(p))<br />
{<br />
ellipseNum = i;<br />
break;<br />
}<br />
}<br />
if (ellipseNum > -1)<br />
{<br />
MessageBox.Show(Convert.ToString(ellipseNum));<br />
displayLine(ellipseNum);<br />
}<br />
else<br />
{<br />
MessageBox.Show("Not currently over any ellipse");<br />
}
Paint event:
StreamReader msbr = new StreamReader(new FileStream(@XMLmonsterSetBaseLocation, FileMode.Open));<br />
<br />
while ((MapMonsterSetBaseData = msbr.ReadLine()) != null)<br />
{<br />
String[] TxtPiecesMap = MapMonsterSetBaseData.Split('\t');<br />
<br />
checkIf(MapMonsterSetBaseData);<br />
<br />
if (checkIfStatus == true)<br />
{<br />
MapXCord = Convert.ToInt16(TxtPiecesMap[3]) * 2;<br />
MapYCord = Convert.ToInt16(TxtPiecesMap[4]) * 2;<br />
<br />
Graphics g = e.Graphics;<br />
<br />
Rectangle r = new Rectangle(MapXCord, MapYCord, 6, 6);<br />
<br />
g.DrawEllipse(Pens.Gold, r);<br />
<br />
mapRectangleList.Add(r);<br />
}
And my checkif
private void checkIf(string data)<br />
{<br />
if (data != "" && data.Length != 3 && data != "end" && data.Substring(0, 1) != "/" && data.Length != 1)<br />
{<br />
checkIfStatus = true;<br />
}<br />
else<br />
{<br />
checkIfStatus = false;<br />
}<br />
}
Dont know if this makes any sense
There might be an easier soloution, but I dont know it
Its allmost the same problem as before, but in a diffrent context
|
|
|
|
|
Hi,
I'm building a program that needs to constantly update using a timer.
In order to make the updating exclusive to the rest of the program, I want to do it on a different thread.
How would I go about adding an event to another thread?
Is it as simple as adding the event and method to the timer in the new thread?
Cheers,
|
|
|
|